{"id":13403209,"url":"https://github.com/johnpapa/lite-server","last_synced_at":"2025-05-14T01:10:46.016Z","repository":{"id":39636003,"uuid":"44478604","full_name":"johnpapa/lite-server","owner":"johnpapa","description":"Lightweight node server","archived":false,"fork":false,"pushed_at":"2024-04-25T22:41:49.000Z","size":318,"stargazers_count":2317,"open_issues_count":74,"forks_count":267,"subscribers_count":54,"default_branch":"main","last_synced_at":"2025-04-03T01:44:33.620Z","etag":null,"topics":["browsersync","devserver","devtools","nodejs","npm","tools","web"],"latest_commit_sha":null,"homepage":"","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/johnpapa.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-18T13:14:44.000Z","updated_at":"2025-03-23T00:58:16.000Z","dependencies_parsed_at":"2024-06-18T11:08:54.193Z","dependency_job_id":"bdb37eaa-a6c4-44d8-b78c-c4b1b29d9849","html_url":"https://github.com/johnpapa/lite-server","commit_stats":{"total_commits":99,"total_committers":17,"mean_commits":5.823529411764706,"dds":0.595959595959596,"last_synced_commit":"5b73f88c6b7e4dc5e3dc481b4bbf7ee553bb0acb"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpapa%2Flite-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpapa%2Flite-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpapa%2Flite-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnpapa%2Flite-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnpapa","download_url":"https://codeload.github.com/johnpapa/lite-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154646,"owners_count":21056541,"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":["browsersync","devserver","devtools","nodejs","npm","tools","web"],"created_at":"2024-07-30T19:01:26.834Z","updated_at":"2025-04-10T03:40:08.949Z","avatar_url":"https://github.com/johnpapa.png","language":"JavaScript","readme":"# lite-server\n\nLightweight _development only_ node server that serves a web app, opens it in the browser, refreshes when html or javascript change, injects CSS changes using sockets, and has a fallback page when a route is not found.\n\n[![Dependency Status](https://david-dm.org/johnpapa/lite-server.svg)](https://david-dm.org/johnpapa/lite-server)\n[![npm version](https://badge.fury.io/js/lite-server.svg)](http://badge.fury.io/js/lite-server)\n[![Build Status](https://travis-ci.org/johnpapa/lite-server.svg?branch=main)](https://travis-ci.org/johnpapa/lite-server) [![Greenkeeper badge](https://badges.greenkeeper.io/johnpapa/lite-server.svg)](https://greenkeeper.io/)\n[![Build Status](https://dev.azure.com/johnpapa/lite-server/_apis/build/status/johnpapa.lite-server?branchName=main)](https://dev.azure.com/johnpapa/lite-server/_build/latest?definitionId=4\u0026branchName=main\u0026WT.mc_id=liteserver-github-jopapa)\n\n## Why\n\nBrowserSync does most of what we want in a super fast lightweight development server. It serves the static content, detects changes, refreshes the browser, and offers many customizations.\n\nWhen creating a SPA there are routes that are only known to the browser. For example, `/customer/21` may be a client side route for an Angular app. If this route is entered manually or linked to directly as the entry point of the Angular app (aka a deep link) the static server will receive the request, because Angular is not loaded yet. The server will not find a match for the route and thus return a 404. The desired behavior in this case is to return the `index.html` (or whatever starting page of the app we have defined). BrowserSync does not automatically allow for a fallback page. But it does allow for custom middleware. This is where `lite-server` steps in.\n\n`lite-server` is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.\n\n## Installation and Usage\n\nThe recommended installation method is a local NPM install for your project:\n\n```bash\nnpm install lite-server --save-dev\nyarn add lite-server --dev # or yarn\n```\n\n...and add a \"script\" entry within your project's `package.json` file:\n\n```json\n# Inside package.json...\n  \"scripts\": {\n    \"dev\": \"lite-server\"\n  },\n```\n\nWith the above script entry, you can then start `lite-server` via:\n\n```bash\nnpm run dev\n```\n\nOther options for running locally installed NPM binaries is discussed in this Stack Overflow question: [How to use package installed locally in node_modules](http://stackoverflow.com/q/9679932)\n\n### Using on the fly\n\nlite-server can be used with `npx`\n\n```bash\nnpx lite-server\n```\n\n### Global Installation\n\nlite-server can be also installed globally, if preferred:\n\n```bash\nnpm install --global lite-server\n\n# To run:\nlite-server\n```\n\n## Custom Configuration\n\nThe default behavior serves from the current folder, opens a browser, and applies a HTML5 route fallback to `./index.html`.\n\nlite-server uses [BrowserSync](https://www.browsersync.io/), and allows for configuration overrides via a local `bs-config.json` or `bs-config.js` file in your project.\n\nYou can provide custom path to your config file via `-c` or `--config=` run time options:\n\n```bash\nlite-server -c configs/my-bs-config.js\n```\n\nFor example, to change the server port, watched file paths, and base directory for your project, create a `bs-config.json` in your project's folder:\n\n```json\n{\n  \"port\": 8000,\n  \"files\": [\"./src/**/*.{html,htm,css,js}\"],\n  \"server\": { \"baseDir\": \"./src\" }\n}\n```\n\nYou can also provide custom path to your base directory `--baseDir=` run time options:\n\n```bash\nlite-server --baseDir=\"dist\"\n```\n\nA more complicated example with modifications to the server middleware can be done with a `bs-config.js` file, which requires the `module.exports = { ... };` syntax:\n\n```js\nmodule.exports = {\n  server: {\n    middleware: {\n      // overrides the second middleware default with new settings\n      1: require('connect-history-api-fallback')({\n        index: '/index.html',\n        verbose: true,\n      }),\n    },\n  },\n};\n```\n\nThe `bs-config.js` file may also export a function that receives the lite-server Browsersync instance as its only argument. While not required, the return value of this function will be used to extend the default lite-server configuration.\n\n```js\nmodule.exports = function (bs) {\n  return {\n    server: {\n      middleware: {\n        // overrides the second middleware default with new settings\n        1: require('connect-history-api-fallback')({\n          index: '/index.html',\n          verbose: true,\n        }),\n      },\n    },\n  };\n};\n```\n\n**NOTE:** Keep in mind that when using middleware overrides the specific middleware module must be installed in your project. For the above example, you'll need to do:\n\n```bash\nnpm install connect-history-api-fallback --save-dev\n```\n\n...otherwise you'll get an error similar to:\n\n```bash\nError: Cannot find module 'connect-history-api-fallback'\n```\n\nAnother example: To remove one of the [default middlewares](./lib/config-defaults.js), such as `connect-logger`, you can set it's array index to `null`:\n\n```js\nmodule.exports = {\n  server: {\n    middleware: {\n      0: null, // removes default `connect-logger` middleware\n    },\n  },\n};\n```\n\nA list of the entire set of BrowserSync options can be found in its docs: \u003chttp://www.browsersync.io/docs/options/\u003e\n\n## Testing\n\nWhen using `lite-server` to run end to end tests, we may not want to log verbosely. We may also want to prevent the browser from opening. These options in the `bs-config.js` will silence all logging from `lite-server`:\n\n```js\n  open: false\n  logLevel: \"silent\",\n  server: {\n    middleware: {\n      0: null\n    }\n  }\n```\n\n## Known Issues\n\nCSS with Angular 2 is embedded thus even though BrowserSync detects the file change to CSS, it does not inject the file via sockets. As a workaround, `injectChanges` defaults to `false`.\n\n## Contributing\n\n1. Fork and clone it\n1. Install dependencies: `npm install`\n1. Create a feature branch: `git checkout -b new-feature`\n1. Commit changes: `git commit -am 'Added a feature'`\n1. Run static code analysis and unit tests: `npm test`\n1. Push to the remote branch: `git push origin new-feature`\n1. Create a new [Pull Request](https://github.com/johnpapa/lite-server/pull/new/main)\n\n## License\n\nCode released under the [MIT license](./LICENSE).\n","funding_links":[],"categories":["JavaScript","Special Thanks"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnpapa%2Flite-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnpapa%2Flite-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnpapa%2Flite-server/lists"}