{"id":13746916,"url":"https://github.com/sloria/local-repl","last_synced_at":"2025-04-07T11:04:42.711Z","repository":{"id":48353990,"uuid":"89806339","full_name":"sloria/local-repl","owner":"sloria","description":"🐚 Project-specific configuration for the Node.js REPL","archived":false,"fork":false,"pushed_at":"2021-07-30T12:12:58.000Z","size":820,"stargazers_count":152,"open_issues_count":9,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-22T20:32:43.587Z","etag":null,"topics":["configuration","node","nodejs","repl","shell"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/local-repl","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sloria.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-29T19:01:00.000Z","updated_at":"2024-02-13T21:29:40.000Z","dependencies_parsed_at":"2022-08-24T14:49:45.658Z","dependency_job_id":null,"html_url":"https://github.com/sloria/local-repl","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sloria%2Flocal-repl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sloria%2Flocal-repl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sloria%2Flocal-repl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sloria%2Flocal-repl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sloria","download_url":"https://codeload.github.com/sloria/local-repl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640462,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","node","nodejs","repl","shell"],"created_at":"2024-08-03T06:01:05.063Z","updated_at":"2025-04-07T11:04:42.680Z","avatar_url":"https://github.com/sloria.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","shell","Javascript"],"sub_categories":["npm packages"],"readme":"# 🐚 local-repl\n\n[![Current Version](https://badgen.net/npm/v/local-repl)](https://www.npmjs.org/package/local-repl)\n[![Build Status](https://badgen.net/travis/babel/babel/master)](https://travis-ci.org/sloria/local-repl)\n[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\u0026repo=sloria/local-repl)](https://dependabot.com)\n\nProject-specific REPLs for Node.js. `local-repl` allows you to automatically import modules and values into your REPL sessions with simple configuration in your project's `package.json` and/or `.replrc.js`.\n\n## Features!\n\n- Automatically import modules into your REPL sessions\n- Use `await` in the REPL without having to wrap your code in async functions\n- Configure the banner and prompt\n\n\n## Add local-repl to your project\n\n```\n$ npm install local-repl --save-dev\n# OR\n$ yarn add local-repl --dev\n```\n\nAdd the following to `package.json`. Note: lodash is used as an example\nhere; it is not required to use local-repl.\n\n```json\n{\n  \"scripts\": {\n    \"repl\": \"local-repl\"\n  },\n  \"devDependencies\": {\n    \"local-repl\": \"^3.0.0\"\n  },\n  \"dependencies\": {\n    \"lodash\": \"^4.17.4\"\n  },\n  \"repl\": [\n    \"lodash\"\n  ]\n}\n```\n\n## Run it\n\n```\n$ npm run repl\n```\n\nThis will start a REPL session with `lodash` already imported.\n\n![](media/basic.gif)\n\n## Specifying aliases\n\nYou can pass an array of objects containing the keys `\"name\"` (required), `\"module\"` (for imports), or `\"value\"` (for values).\n\n```json\n{\n  \"repl\": [\n    {\"name\": \"l\", \"module\": \"lodash\"},\n    {\"name\": \"meaningOfLife\", \"value\": 42}\n  ]\n}\n```\n\n![](media/aliases.gif)\n\n## Importing local modules\n\nLocal modules can be imported, too.\n\n```json\n{\n  \"repl\": [\n    {\"name\": \"project\", \"module\": \"./\"},\n    {\"name\": \"utils\", \"module\": \"./lib/utils\"}\n  ]\n}\n```\n\n## Using `.replrc.js`\n\nInstead of defining configuration in \"package.json\", you may define your configuration in a `.replrc.js` file. This is useful if you want to dynamically compute modules and values for your REPLs.\n\n```js\n// .replrc.js\nconst User = require('./myapp/models/User');\n\nmodule.exports = {\n  context: [\n    'lodash',\n    'myapp/utils',\n    {name: 'me', value: User.getByEmail('sloria')},\n  ]\n}\n```\n\n**Note**: Configuration defined in `.replrc.js` takes precedence over configuration defined in `package.json`.\n\n\n## Defining context as an object\n\nContext can be defined as an object rather than an array.\n\n```javascript\n// .replrc.js\nconst User = require('./myapp/models/User');\n\nmodule.exports ={\n  context: {\n    l: require('lodash'),\n    utils: require('myapp/utils'),\n    me: User.getByEmail('sloria'),\n  }\n}\n```\n\n## Promises as context values\n\nContext values that are promises will be resolved before the REPL starts.\n\n```javascript\n// .replrc.js\nconst promise = new Promise((resolve) =\u003e {\n  setTimeout(() =\u003e {\n    resolve(42);\n  }, 500);\n});\n\nmodule.exports = {\n  // REPL will have meaningOfLife with value 42 in context\n  context: {\n    meaningOfLife: promise,\n  }\n};\n```\n\n## await support\n\nYou can use `await` in your REPL sessions without having to\ncreate `async` functions.\n\n![](media/await.gif)\n\nJust add the following to your package.json:\n\n```json\n{\n  \"repl\": {\n    \"enableAwait\": true\n  }\n}\n```\n\nOr in `.replrc.js`\n\n```js\n// .replrc.js\nmodule.exports = {\n  enableAwait: true\n}\n\n```\n\n## More configuration\n\n### Configuring the prompt\n\nIn package.json:\n\n```json\n{\n  \"repl\": {\n    \"prompt\": \"myproject $\"\n  }\n}\n```\n\nIn `.replrc.js`:\n\n```javascript\n// .replrc.js\nmodule.exports = {\n  prompt: 'myproject $'\n}\n```\n\nYou can also define `prompt` as a function in `.replrc.js`. The function will receive the REPL context and the parsed `package.json` object.\n\n```javascript\n// .replrc.js\nmodule.exports = {\n  prompt: (context, pkg) =\u003e {\n    return `${pkg.name} ${pkg.version} $`\n  }\n}\n```\n\n### Configuring the banner\n\nIn package.json:\n\n```json\n{\n  \"repl\": {\n    \"banner\": \"Welcome to the myapp REPL. Happy hacking!\"\n  }\n}\n```\n\nYou can also define `banner` as a function in `.replrc.js`. The function will receive the REPL context and the parsed `package.json` object.\n\n```javascript\n// .replrc.js\nconst _ = require('lodash');\nconst chalk = require('chalk');\n\nmodule.exports = {\n  context: [\n    {name: 'l', value: _},\n    {name: 'meaningOfLife', value: 42},\n  ],\n  banner: (context, pkg) =\u003e {\n    console.log(chalk.bold(`Welcome to the REPL for myapp ${pkg.version}.`));\n    console.log(chalk.green('Happy hacking!'));\n    console.log(chalk.cyan('Context:'), _.keys(context).sort().join(', '));\n  }\n}\n```\n\n![](media/banner.png)\n\n## Programmatic usage\n\n`local-repl` can be used programatically. The `.start(options)` function takes the same options as Node's built-in [`repl.start(options)`](https://nodejs.org/api/repl.html#repl_repl_start_options) and returns a `Promise` that resolves to a `REPLServer` instance.\n\n```javascript\nconst repl = require('local-repl');\n\nrepl.start({ prompt: '\u003c -_- \u003e ' });\n```\n\n## Inspiration\n\n`local-repl` is inspired a number of other great projects:\n\n- [konch](https://github.com/sloria/konch) - REPL configuration for Python\n- [n_](https://github.com/borisdiakur/n_) - Node.js REPL with lodash\n\n## License\n\nMIT licensed. See [LICENSE](https://github.com/sloria/local-repl/blob/master/LICENSE) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsloria%2Flocal-repl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsloria%2Flocal-repl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsloria%2Flocal-repl/lists"}