Coder Social home page Coder Social logo

lite-server's Introduction

lite-server

Lightweight 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.

Dependency Status npm version Build Status Greenkeeper badge Build Status

Why

BrowserSync 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.

When 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.

lite-server is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.

Installation and Usage

The recommended installation method is a local NPM install for your project:

npm install lite-server --save-dev
yarn add lite-server --dev # or yarn

...and add a "script" entry within your project's package.json file:

# Inside package.json...
  "scripts": {
    "dev": "lite-server"
  },

With the above script entry, you can then start lite-server via:

npm run dev

Other options for running locally installed NPM binaries is discussed in this Stack Overflow question: How to use package installed locally in node_modules

Using on the fly

lite-server can be used with npx

npx lite-server

Global Installation

lite-server can be also installed globally, if preferred:

npm install --global lite-server

# To run:
lite-server

Custom Configuration

The default behavior serves from the current folder, opens a browser, and applies a HTML5 route fallback to ./index.html.

lite-server uses BrowserSync, and allows for configuration overrides via a local bs-config.json or bs-config.js file in your project.

You can provide custom path to your config file via -c or --config= run time options:

lite-server -c configs/my-bs-config.js

For 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:

{
  "port": 8000,
  "files": ["./src/**/*.{html,htm,css,js}"],
  "server": { "baseDir": "./src" }
}

You can also provide custom path to your base directory --baseDir= run time options:

lite-server --baseDir="dist"

A more complicated example with modifications to the server middleware can be done with a bs-config.js file, which requires the module.exports = { ... }; syntax:

module.exports = {
  server: {
    middleware: {
      // overrides the second middleware default with new settings
      1: require('connect-history-api-fallback')({
        index: '/index.html',
        verbose: true,
      }),
    },
  },
};

The 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.

module.exports = function (bs) {
  return {
    server: {
      middleware: {
        // overrides the second middleware default with new settings
        1: require('connect-history-api-fallback')({
          index: '/index.html',
          verbose: true,
        }),
      },
    },
  };
};

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:

npm install connect-history-api-fallback --save-dev

...otherwise you'll get an error similar to:

Error: Cannot find module 'connect-history-api-fallback'

Another example: To remove one of the default middlewares, such as connect-logger, you can set it's array index to null:

module.exports = {
  server: {
    middleware: {
      0: null, // removes default `connect-logger` middleware
    },
  },
};

A list of the entire set of BrowserSync options can be found in its docs: http://www.browsersync.io/docs/options/

Testing

When 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:

  open: false
  logLevel: "silent",
  server: {
    middleware: {
      0: null
    }
  }

Known Issues

CSS 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.

Contributing

  1. Fork and clone it
  2. Install dependencies: npm install
  3. Create a feature branch: git checkout -b new-feature
  4. Commit changes: git commit -am 'Added a feature'
  5. Run static code analysis and unit tests: npm test
  6. Push to the remote branch: git push origin new-feature
  7. Create a new Pull Request

License

Code released under the MIT license.

lite-server's People

Contributors

andreasonny83 avatar azureadvocatebit avatar cgmartin avatar dependabot[bot] avatar fvilers avatar greenkeeper[bot] avatar johnpapa avatar josefjura avatar kevinjamesus86 avatar michaelmainer avatar qubithaze avatar stephanmg avatar valorkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lite-server's Issues

Rewrite only requests for html files

When SystemJS is misconfigured and it tries to fetch modules via URLs that don't map to js files, lite-server redirects the requests to index.html (or /) in order to support the window.history.pushState location strategy.

The problem with this is that System will typically error with a weird error like Uncaught SyntaxError: Unexpected token <. This error is very difficult to understand and fix.

It would be much better if lite-server error with 404s in this case, giving the developer the correct feedback that the file is not present at this url. This should be achieved without breaking the pushState support for location by distinguishing the SystemJS requests from the application requests. SystemJS makes all requests with Accept: application/x-es-module, */* request header and we can use this to identify these requests and treat them differently from others.

This kind of treatment of different requests might be useful for other kinds of errors in general (e.g. image fetches). So it might actually be better to change the server to rewrite only requests with request header Accept:text/html,application/xhtml+xml,... which is typically used by the browser to fetch the initial html (which is the only thing we want to rewrite).

screen shot 2016-03-14 at 5 10 31 pm
screen shot 2016-03-14 at 5 11 57 pm

enable bs-config.json comments

currently tsconfig.json, typings.json and .vscode/launch.json + settings.json + tasks.json all support use of // and /* */ comments to store details of alternative settings and notes relating to contents of those files.

i tried doing this in lite-server dependent bs-config.json, e.g. as in following example, and this breaks 'npm run lite-server' support.

{ 
  "port": 3000,  // == default and for specific port use "port": 8080 or "https": true, "port": 44300,
  //"files": ["./src/**/*.{html,htm,css,js}"],
  "files": ["./**/*.{html,htm,css,js}"],
  //"server": { "baseDir": "./src" }
  "server": { "baseDir": "./" }
}

is enabling similar support in lite-server dependent bs-config.json file something that is in the plans already?

would it be change that has to happen in the https://github.com/johnpapa/lite-server or https://github.com/browsersync/browser-sync package release work?

referencing node_modules outside base path

In an angular 2 application with structure as
app
|-- node_modules
|-- src
|-- index.html

and bs-config as
"server": { "baseDir": "./src" }

How do I reference the angular sources in my index.html which are outside my base path.
If i give base path as "/", then I have to invoke the url with /src/index.html always.

Errors Installing

I have Python2.7.11 for Windows x86/x64 installed on Windows 7 x64. When I run npm install lite-server --save-dev, I get the following errors:
TypeError: Request path contains unescaped characters.

And a few 404 status codes downloading 32-bit node.libs.

Some exceptions while running angular 2 quickstart

[1] events.js:72
[1] throw er; // Unhandled 'error' event
[1]
[1] ^
[1] Error: watch ENOSPC
[1] at errnoException (fs.js:1031:11)
[1] at FSWatcher.start (fs.js:1063:11)
[1] at Object.fs.watch (fs.js:1088:11)
[1] at createFsWatchInstance (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:37:15)
[1] at setFsWatchListener (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:80:15)
[1] at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:228:14)
[1] at FSWatcher.NodeFsHandler._handleDir (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:407:19)
[1] at FSWatcher. (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:455:19)
[1] at FSWatcher. (/home/ee/a2/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/lib/nodefs-handler.js:460:16)
[1] at Object.oncomplete (fs.js:108:15)
[1] npm
[1] ERR! weird error 8
[1] npm
[1] ERR! not ok code 0
[1] npm run lite exited with code 1

i have only one instance of lite-server running. What chan happens?

Quotes around parameters not working on Windows

My partner has to work on a Windows environment, and was having trouble to start up the lite server. There were no errors in the console, but the only thing displayed in the browser was Cannot GET /.

lite-server --port 8080 --baseDir './dist/dev' --files './dist/dev/**/*'

Problem with network drives

Hey everyone,
I try to run a lite-server instance which is supposed to serve files from a network-connected NTFS-drive.

This is my setup. It is based o the README-Guide. deleted

The Problem

At first, it starts fine. But after about 8 to 10 seconds, lite-server crashes.

Running npm install lite-server -g didn't help.

If i try to run it from a local harddrive, it works completely fine.

The Output

Console:
U:\lite_network-test>npm run dev

> [email protected] dev U:\lite_network-test
> lite-server

Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync options **
{ injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  server: { baseDir: './', middleware: [ [Function], [Function] ] } }
[BS] Access URLs:
 ---------------------------------------
       Local: http://localhost:3000
       External: http://172.27.209.218:3000
 ---------------------------------------
          UI: http://localhost:3001
          UI External: http://172.27.209.218:3001
 ---------------------------------------
[BS] Serving files from: ./
[BS] Watching files...
16.03.01 10:55:21 304 GET /index.html
events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: watch null UNKNOWN
    at exports._errnoException (util.js:856:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1296:21)

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v5.7.0
npm ERR! npm  v3.6.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: `lite-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'lite-server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the lite-server_network-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     lite-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs lite-server_network-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls lite-server_network-test
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     U:\lite_network-test\npm-debug.log
npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]~predev: [email protected]
6 silly lifecycle [email protected]~predev: no script for predev, continuing
7 info lifecycle [email protected]~dev: [email protected]
8 verbose lifecycle [email protected]~dev: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~dev: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;U:\lite_network-test\node_modules\.bin;C:\Program Files\ConEmu;C:\Program Files\ConEmu\ConEmu;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Box\Box Edit\;C:\Program Files (x86)\IXOS\bin;C:\Program Files\nodejs\;C:\Users\luca.vazzano\Programs\apache-maven-3.3.3\bin;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files\setlX;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;C:\Users\luca.vazzano\AppData\Roaming\npm;C:\Users\luca.vazzano\AppData\Local\Pandoc\
10 verbose lifecycle [email protected]~dev: CWD: U:\lite_network-test
11 silly lifecycle [email protected]~dev: Args: [ '/d /s /c', 'lite-server' ]
12 silly lifecycle [email protected]~dev: Returned: code: 1  signal: null
13 info lifecycle [email protected]~dev: Failed to exec dev script
14 verbose stack Error: [email protected] dev: `lite-server`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:232:16)
14 verbose stack     at emitTwo (events.js:100:13)
14 verbose stack     at EventEmitter.emit (events.js:185:7)
14 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack     at emitTwo (events.js:100:13)
14 verbose stack     at ChildProcess.emit (events.js:185:7)
14 verbose stack     at maybeClose (internal/child_process.js:827:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid [email protected]
16 verbose cwd U:\lite_network-test
17 error Windows_NT 6.1.7601
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
19 error node v5.7.0
20 error npm  v3.6.0
21 error code ELIFECYCLE
22 error [email protected] dev: `lite-server`
22 error Exit status 1
23 error Failed at the [email protected] dev script 'lite-server'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the lite-server_network-test package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     lite-server
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs lite-server_network-test
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls lite-server_network-test
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

lite-server folder structure causing file path length issues

Using the current Angular2 Quickstart for Typescript
https://github.com/angular/quickstart/blob/master/README.md
It is difficult to create a fully installed node_modules with npm because within the folder there are several subfolders with path lengths so long that they can not be copied into a Windows 10 folder structure without placing them in a folder with a name of about 6 characters or fewer at the very root of the drive. I discovered this while trying to port the project to Visual Studio 2015. I noticed that using GIT Bash to perform the NPM Install worked, however the content of the node_modules folder could not be copied after that without errors.
A couple of examples of folders in this category are balanced-match, concat-map and color-convert.

os Windows 10
git version 2.7.4.windows.1
Visual Studio 2015 Update 1
Visual Studio Code

Respect shell colors

You use connect-logger, which is using hard coded color values to do logging of files, but not hardcoded background colors, which results in conflicts with often used themes, such as solarized (i cant read the filename of a watched file, since it has the same color as the background).

It would be great it you could either:

  • provide an option to turn colors off
  • set the background as well(worst option, but better than nothing)
  • respect the shells colors and use the default foreground color, instead of hardcoding a black.

Rename lite-server to identify it as a quick, easy, simple, demo server not for production use

There has been confusion on the purpose of lite-server. We get asked about using lite-server with IIS, using it to be a full fledged production server, how to deploy it. lite-server is intended to be a server for:

  1. demo use
  2. quick and easy server without having to write any server code
  3. help you focus on writing client code

It is not intended for anything beyond this.

Perhaps we should rename it to demo-server ?

Specifying the --port flag seems to have no effect

The --port flag seems to have no effect:
$ lite-server --verbose --port=8081
options { port: 8081,
openPath: '.',
files: [ './/*.html', './/.css', './__/.js' ],
baseDir: './',
fallback: '/./index.html' }
[BS] Access URLs:


   Local: http://localhost:3000
External: http://<my-ip>:3000

      UI: http://localhost:3001

UI External: http://:3001


So the console output looks as though the server is listening on ports 3000 and 3001 and netstat supports that:
$ netstat -at
tcp6 0 0 [::]:3000 [::]:* LISTEN
tcp6 0 0 [::]:3001 [::]:* LISTEN

Does browser-sync not support the port option properly?

When rebuilding a project, browser window shows Cannot GET /

I assume this has to do with the fact that my build process removes the destination directory before building, which is the directory lite-server is watching. Then, it displays Cannot GET / on the browser window and doesn't refresh anymore after the build is complete.

Is there anything that can be done about this?

lite-server & gulp

Hi John,

What is your suggestion for using lite-server with Gulp,
can you please provide me with and example?

"Class not registered" error when running lite-server on Windows

I have installed lite-server using "npm install -g lite-server" on my Windows 8.1
When I now run "npm run lite" a window opens and says:

http://localhost:3002
Class not registered

But the server runs and I can browse on http://localhost:3000

Environment

  • lite-server version: 2.1.0
  • nodejs version: 0.10.36
  • npm version: 1.4.28
  • OS type/version: Windows 8.1 Pro 64 bit

This is the output of the command line (windows shell):

> lite-server

Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync config **
{ injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  watchOptions: { ignored: 'node_modules' },
  server: { baseDir: './', middleware: [ [Function], [Function] ] } }
[BS] Access URLs:
 --------------------------------------
       Local: http://localhost:3002
    External: http://192.168.1.117:3002
 --------------------------------------
          UI: http://localhost:3003
 UI External: http://192.168.1.117:3003
 --------------------------------------
[BS] Serving files from: ./
[BS] Watching files...

Screenshot of the error message window: http://s29.postimg.org/q3kvc85np/errmsg.png

The ability to inject watchers/renderers that trigger browser-sync reloads would be nice

I was really pleased to discover lite-server via the Angular 2 documentation.

It would be nice to be able to inject watchers/renderers that would trigger browser-sync reload events. Currently, I'm not aware of any way elegantly to use CSS preprocessing in conjunction with lite-server.

One solution I found was to add something like this

if (argv.watcher) {
  var fs = require('fs');
  try {
    fs.accessSync(process.cwd() + '/' + argv.watcher, fs.F_OK);
    require(process.cwd() + '/' + argv.watcher)(function() {
      sync.reload();
    });
  } catch (e) {
    console.log(e);
  }
}

to lite-server.js. I was then able to pass in a watcher file (--watcher './ls-watcher.js') that watched my project folders for changes to.less` files, rendered the Less to CSS, and then triggered the page reload via the callback. Of course, there are many other use-cases beyond this one, too.

Do you think that something like this might be a useful addition to the code base? If so, I can submit a PR.

Edit: See PR #20.

Edit 2: I realize now that triggering the reload method may be redundant (if the files are already being watched per the config), but not always--and the main functionality of this would be the ability to include a rendering process (or many).

Server-Side rendering support?

This could be a stupid question. But I really would like to know if lite-server support Server-side rendering in somehow.

Thanks in advance.

proxy

its more of a question than an issue...

I am following the NG2 ToH pattern and need to add a proxy to my local server API but would like to keep it simple from the command prompt in the node script section of the package.json

any url calls to /server/api
redirect to
http://192.168.99.100/server/api

thanks

2.1.0 works, 2.2.0 doesn't. No errors given

I hate to be vague, but when I am using 2.2.0 lite-server doesn't open a browser tab in Chrome, hitting the URL results in ERR_CONNECTION_REFUSED, and I don't see anything helpful in the terminal log. I delete lite-server and install 2.1.0 and everything is normal. Is there a way to turn on logging or something?

gulpfile:

gulp.task('server', serverTask);

function serverTask() {
    // To require this is to execute it.
    require('lite-server');
}

bs-config:

{
  "notify": false,
  "port": 1337,
  "files": ["./dist/**/*{html,css,js}"],
  "server": {
    "baseDir": "dist"
  }
}

Installing lite-server error Can't find python executable

I am unable to install lite-server. I get an error that node-gyp can't find the python executable. The only solution I find online is to install python and C++ and Windows SDK and build it from scratch. Am I missing something?

option to start lite server w/o launching browser

is there a switch i'm overlooking that would enable starting lite server w/o launching browser?

the reason for this ask is so that from command line I can launch lite server and then from vscode I can use chrome extension to start and attach to that browser instances pointed at lite server address.

this can be repro'd using https://github.com/myusrn/vscng2qs which is simple https://angular.io/docs/ts/latest/quickstart.html based solution that has package.json configured to allow "npm run lite" from command line to start server, where I don't want it kicking off browser, so I can then move to vscode and use debug | "Launch localhost with sourcemaps" option to kick off instance of chrome pointed at that server.

Redirect-loop to root

From the angular tutorial, I was told to use "npm start" which runs:

concurrent "npm run tsc:w" "npm run lite"

if I move the content of my app into a subfolder and redirect there, I'm getting into a loop. Somehow the file index-file from the root folder is delivered at the app-subfolder as well. I thought I misconfigured something, but another http-server (serve) doesn't do that and brings me straight into the app.

Am I missing something? I saw that you can pass the subfolder to serve, but I need some files at the root, so this is not an option.

Thanks.

Gulp integration

Couple of questions:

  • Can lite-server be used in Gulp without a plugin?
  • If not, is there a gulp-lite-server plugin available?
  • If not, do you think it would be useful to have a plugin? I could prob create one over the weekend.

Crashes When Trying To Load Angular2 5min Tutorial Code

I couldn't make it work with angular code using both local and global installation, via npm and by calling it directly.

The execution always stops on unhandled exception:

'''
events.js:154
throw er; // Unhandled 'error' event
^
Error: watch node_modules/insight/node_modules/lodash/internal/LodashWrapper.js ENOSPC
at exports._errnoException (util.js:856:11)at FSWatcher.start (fs.js:1313:19)
at Object.fs.watch (fs.js:1341:11)at createFsWatchInstance (/node_modules/chokidar/lib/nodefs-handler.js:37:15)
at setFsWatchListener (/node_modules/chokidar/lib/nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (/node_modules/chokidar/lib/nodefs-handler.js:228:14)
at FSWatcher.NodeFsHandler._handleFile (/node_modules/chokidar/lib/nodefs-handler.js:255:21)
at FSWatcher. (/node_modules/chokidar/lib/nodefs-handler.js:473:21)
at FSReqWrap.oncomplete (fs.js:82:15)
'''

npm-debug.log:

[0] info it worked if it ends with ok
[1] verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'lite' ]
[2] info using [email protected]
[3] info using [email protected]
[4] verbose run-script [ 'prelite', 'lite', 'postlite' ]
[5] info lifecycle [email protected]prelite: [email protected]
[6] silly lifecycle [email protected]
prelite: no script for prelite, continuing
[7] info lifecycle [email protected]lite: [email protected]
[8] verbose lifecycle [email protected]
lite: unsafe-perm in lifecycle true
[11] silly lifecycle [email protected]lite: Args: [ '-c', 'lite-server' ]
[12] silly lifecycle [email protected]
lite: Returned: code: 1 signal: null
[13] info lifecycle [email protected]~lite: Failed to exec lite script
[14] verbose stack Error: [email protected] lite: lite-server
[15] verbose stack Exit status 1
[16] verbose stack at EventEmitter. (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
[17] verbose stack at emitTwo (events.js: 100:13)
[18] verbose stack at EventEmitter.emit (events.js:185:7)
[19] verbose stack at ChildProcess. (/usr/lib/node_modules/npm/lib/utils/spawn.js:24:14)
[20] verbose stack at emitTwo (events.js: 100:13)
[21] verbose stack at ChildProcess.emit (events.js:185:7)
[22] verbose stack at maybeClose (internal/child_process.js:827:16)
[23] verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
[24] verbose pkgid [email protected]
[25] verbose cwd /home/tyshkev/code/study/angular/quickstart
[26] error Linux 3.19.0-49-generic
[27] error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "lite"
[28] error node v5.6.0
[29] error npm v3.6.0
[30] error code ELIFECYCLE
[31] error [email protected] lite: lite-server
[32] error Exit status 1
...
[33] verbose exit [ 1, true ]

This doesn't happen when angular is not included on the page.
Same package configuration with browser-sync v2.11.1 has no issues.

Expose BrowserSync or Create custom script

Let's track our ideas in an issue and propose either a way to expose BS entirely or use a fully custom script that deprecates lite-server.

Goals:

  • a quick/fast server
  • serves static assets
  • handle fallback routes for SPAs
  • exposes all browser-sync features (dont recreate the wheel)
  • doesn't collide with simultaneous watchers from transpilers like TypeScript or babel
  • minimalistic (run via NPM script)

The biggest advantage to having an npm package is that we can npm install lite-server and we have it. if we go the route of having a script and deprecate lite-server, we need to npm install both the fallback package and browsersync + have a short script that runs them together. This is the crux of it.

cc / @cgmartin

Thanks Guys!

Accidentally stumbled upon this gem, just what I was looking for today :-)

story for launching lite-server as part of visual studio code launch.json settings

love the lite-server story especially as outlined for use in https://angular.io/docs/ts/latest/quickstart.html and related ng2 getting started tutorials.

was wondering if you'd arrived at a way to enable it to be run as part of visual studio code debugger rather than requiring me to drop out to a command prompt and execute "npm start" alias and then resort to browser f12 tools for debugging?

was trying to vet that option in https://github.com/myusrn/vscng2qs but seems like it only wants to launch node.js server apps and not lite-server npm package.

Doesn't work when using the "proxy" config

Here are my configs:

{
    "proxy": "localhost:5000",
    "port": 7000
}

When I run the command without "proxy": "localhost:5000", an instance of Chrome opens on localhost:7000 as expected and everything is fine. With "proxy": "localhost:5000", it shows:

** browser-sync config **
{ injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  watchOptions: { ignored: 'node_modules' },
  server: { baseDir: './', middleware: [ [Function], [Function] ] },
  logLevel: 'silent',
  proxy: 'localhost:5000',
  port: 7000 }

in the terminal and the process exits.

I tested a bit with some console.logs in lite-server.js:

console.log('executed');
browserSync.init(config, cb);
console.log('not executed');

Versions:

  • lite-server version: 2.2.0
  • nodejs version: 5.9.1
  • npm version: 3.7.3
  • OS type/version: OSX El Capitan 10.11.3

Update
I gave version 2.1.0 a try and this time I got much clearer indications: Invalid config. You cannot specify both server & proxy options.

When merging the default config and the custom config, proxy and server are put together in the same set of configurations.

To temporarily fix my problem, I replaced

if (config.server.middleware) {
    config.server.middleware = _.compact(config.server.middleware);
}

by:

delete config.server;

So there are two problems:

  1. The outputs from browser-sync are not being displayed in the terminal (They are displayed in 2.1.0. but not 2.2.0). This includes Invalid config. You cannot specify both server & proxy options, but also the message telling me to add
<script id="__bs_script__">//<![CDATA[
//     document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-    client.2.11.2.js'><\/script>".replace("HOST", location.hostname));
// //]]></script>

before the closing tag of the body when the application actually launches in proxy mode.
2. There is a conflict between the default server config and the proxy config.

Get rid of the Unknowns

When running lite-server, I always see a lot of angry red Unknowns, which makes me think errors are happening while they are not:

ss

Any way to get rid of those, or at least change the color to something less error-like?

lite-server & req.cookies

Hi,

I actually want to use lite-server for my angular2 app development but I need to have localhost cookies ressources passed through req.cookies for each call from service to backend. (to handle user auth) If I use my node server instead of lite-server everything is working but I can't refresh angular routes without haing "cannot get" that's why I want to use lite-server ! Does anyone has an idea of how can I fix my problem ?

Thank you

watches files inside ./node_modules

starting the angular2 quickstart server npm run lite-server watches for changes in node_modules causing it to reload over and over again. Adding a my-bs-config.json with this inside

{
  "files": [
    "./app/**/*.{html,htm,css,js}",
    "./*.{html,css}"
  ]
}

appears to stop it from constantly reloading itself but it still is watching files withing node_modules

[1] [BS] Serving files from: ./
[1] [BS] Watching files...
[1] 16.03.17 13:10:24 304 GET /index.html
[1] 16.03.17 13:10:24 304 GET /styles.css
[1] 16.03.17 13:10:24 304 GET /node_modules/es6-shim/es6-shim.min.js
[1] 16.03.17 13:10:24 304 GET /node_modules/systemjs/dist/system-polyfills.js
[1] 16.03.17 13:10:24 304 GET /node_modules/angular2/es6/dev/src/testing/shims_for_IE.js
[1] 16.03.17 13:10:24 304 GET /node_modules/angular2/bundles/angular2-polyfills.js
[1] 16.03.17 13:10:24 304 GET /node_modules/systemjs/dist/system.src.js
[1] 16.03.17 13:10:24 304 GET /node_modules/rxjs/bundles/Rx.js
[1] 16.03.17 13:10:24 304 GET /node_modules/angular2/bundles/angular2.dev.js
[1] 16.03.17 13:10:24 304 GET /node_modules/angular2/bundles/angular2-polyfills.js
[1] 16.03.17 13:10:24 304 GET /node_modules/systemjs/dist/system.src.js
[1] 16.03.17 13:10:24 304 GET /node_modules/rxjs/bundles/Rx.js
[1] 16.03.17 13:10:24 304 GET /node_modules/angular2/bundles/angular2.dev.js
[1] 16.03.17 13:10:24 304 GET /app/main.js
[1] 16.03.17 13:10:24 304 GET /app/app.component.js

I am running:

linux mint rafaela
node v5.6.0
npm v3.6.0

How to stop verbose output to the console

I have lite-server setup in package.json:

"scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run scss:w\" \"npm run lite\" ",
    "tsc": "tsc --inlineSourceMap --allowSyntheticDefaultImports -outDir .build/js",
    "tsc:w": "tsc -w --inlineSourceMap --allowSyntheticDefaultImports -outDir .build/js",
    "scss": "node-sass --include-path styles/app.scss .build/css/app.css",
    "scss:w": "node-sass -w --include-path styles styles/app.scss .build/css/app.css",
    "lite": "lite-server -c bs-config.json",
    "typings": "typings",
    "postinstall": "typings install"
  },

with the following bs-config.json file:

{
    "notify": false,
    "files": ["./.build/css/*.css", "./.build/js/**/*.js", "./app/**/*.{html,css}", "index.html"],
    "injectChanges": true,
    "logLevel": "silent",
    "debugInfo": false,
    "ghostMode": false,
     "server": { "baseDir": "." }
}

Upon starting I see that the bs-config.json configuration is written to te console:

** browser-sync config **
[2] { injectChanges: true,
[2]   files: 
[2]    [ './.build/css/*.css',
[2]      './.build/js/**/*.js',
[2]      './app/**/*.{html,css}',
[2]      'index.html' ],
[2]   watchOptions: { ignored: 'node_modules' },
[2]   server: { baseDir: '.', middleware: [ [Function], [Function] ] },
[2]   notify: false,
[2]   logLevel: 'silent',
[2]   debugInfo: false,
[2]   ghostMode: false }
[0] 8:02:46 AM - Compilation complete. Watching for file changes.

Since the logLevel is set to silent, I expect to see very little info in the console.
However, each and every get is displayed:

[2] 16.04.23 08:02:50 200 GET /index.html
[2] 16.04.23 08:02:50 304 GET /node_modules/bootstrap/dist/css/bootstrap.min.css
[2] 16.04.23 08:02:50 304 GET /node_modules/font-awesome/css/font-awesome.min.css
[2] 16.04.23 08:02:50 304 GET /node_modules/ng2-notify/dist/css/ng2notify.css
[2] 16.04.23 08:02:50 304 GET /.build/css/app.css
[2] 16.04.23 08:02:50 304 GET /node_modules/es6-shim/es6-shim.min.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/bundles/angular2-polyfills.js
[2] 16.04.23 08:02:50 304 GET /node_modules/systemjs/dist/system-polyfills.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/es6/dev/src/testing/shims_for_IE.js
[2] 16.04.23 08:02:50 304 GET /node_modules/systemjs/dist/system.src.js
[2] 16.04.23 08:02:50 304 GET /node_modules/rxjs/bundles/Rx.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/bundles/angular2.dev.js
etc...

Environment

  • lite-server version: 2.2.0
  • nodejs version: 5.7.1
  • npm version: 3.8.0
  • OS type/version: OSX

404 index.html

I have added folders to my structure going from app => index.html to src => client => app=> index.html. Now all of a sudden I am getting a 404 when I run my script. Example of my package.json below

{
  "name": "haComponentsPage",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "scripts": {
    "start": "lite-server"},
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/router": "^0.1.0",
    "angular": "1.5.0",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "lite-server": "^2.0.1"
  }

}

*** note I am changing the structure from this repository.https://github.com/petebacondarwin/ng1-component-router-demo
For the new component router

Cannot auto refresh upon changes

Hi ,
I followed the tutorial via Angular2 5 mins quickstart.
When i run using the npm start, it is able to run in the browser but it cannot auto refresh the browser whenever it has any changes. It only detects changes but the browser wont auto refresh.
Is there any additional setting that i should include for the browser-sync?

Please advise.

Update engine.io-client dependency to avoid xmlhttprequest dependency which does not work behind corporate proxy

The current dependency for lite-server is to use [email protected] which has a sub-dependency of xmlhttprequest and this module has a known issue for users behind corporate firewall/web-proxy as it apparently ignores the https-proxy config item and tries to connect directly to github.com leading to timeouts:

npm ERR! fetch failed https://github.com/rase-/node-XMLHttpRequest/archive/a6b6f2.tar.gz
npm WARN retry will retry, error on last attempt: Error: tunneling socket could not be established, cause=socket hang up

engine.io-client was updated at end of January 2016 to use xmlhttprequest-ssl dependency instead and fixes the above issue.
Currently engine.io-client v1.6.8 installs properly from behind our corporate firewall and web-proxy.

Hopefully lite-server can be updated to use the newer engine.io-client

Fresh install of lite-server using KoaJS

I've used KoaGenerator to generate a skeleton app for me.

I've installed lite-server.

    "scripts": {
        "c": "babel -d app/ src",
        "tsc": "tsc",
        "tsc:w": "tsc -w",
        "lite": "lite-server --browser chrome --open local",
        "dev": "npm run c && concurrent \"npm run tsc:w\" \"npm run lite\" ",
        "start": "npm run c && ./node_modules/.bin/nodemon app/bin/www"
    },

I currently have this, when I run npm run dev everything runs, but all my routes 404. Any idea where I should look into fixing this? Do I need to already start my server, then run lite-server after? Any information would be great thanks.

Trying to run lite-server

I'm a node.js beginner...i'm trying to use lite-server in my app development.
I downloaded the repository in my app folder and I run lite-server command but nothing happens...can you help me to setup it correctly?

npm ERR! code ELIFECYCLE

[1] npm
[1] ERR!
[1] Linux 4.4.2-301.fc23.x86_64
[1] npm
[1] ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "lite"
[1] npm ERR! node
[1] v5.7.1
[1] npm ERR!
[1] npm v3.8.1
[1] npm ERR! code ELIFECYCLE
[1] npm
[1] ERR! [email protected] lite: lite-server
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the [email protected] lite script 'lite-server'.
[1] npm ERR! Make sure you have the latest version of node.js and npm installed.
[1] npm ERR! If you do, this is most likely a problem with the a2uploads package,
[1] npm ERR! not with npm itself.
[1] npm ERR! Tell the author that this fails on your system:
[1] npm ERR! lite-server
[1] npm ERR! You can get information on how to open an issue for this project with:
[1] npm ERR! npm bugs a2uploads
[1] npm ERR! Or if that isn't available, you can get their info via:
[1] npm ERR! npm owner ls a2uploads
[1] npm ERR! There is likely additional logging output above.
[1]
[1] npm ERR! Please include the following file with any support request:

npm-debug.log.txt

Use HTTP/2 and SPDY

Thanks so much for building this tool, it's really outstandingly useful.

In keeping with the "the future is today" mentality of most of the newer JS frameworks, would you be willing to entertain a PR that introduced support for HTTP/2 and SPDY via node-spdy?

About the 'Why' of lite-server

Hello John,

I have browser-sync already running before I saw your lite-server on the angular 2 hero sample.

You say: "When 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."

But is this not the job of the e.g. asp.net backend to handle the 404 from the pushstate route and return the index.html?

It seems to me from your description that you do the same as this guy:

http://www.eriklieben.com/enabling-pushstate-in-asp-net-vnext/

Is this correct that you do the same because then I do not try the lite-server?!

OutOfMemory exception when using it for about 6 hours

I have observed high CPU (25% on my 8-core CPU) and Memory usage when I use live-server with my simple angular2 application. Very often live-server struggles to server html pages using around 25% on my 8-core CPU and I need to wait for more than 10 seconds to refresh the page. I think this happens only when I have used live-server for about 5-6 hours continuously and only when automatic refresh is initiated because of a change in one of my html files. It happens also when I change some of the .ts files after which they are processed by "tsc -w".

Today it thrown an exception:

[1] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
[1]
[1] npm
[1]  ERR! Windows_NT 6.3.9600
[1] npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\node
js\\node_modules\\npm\\bin\\npm-cli.js" "run" "lite"
[1] npm ERR! node v5.3.0
[1] npm ERR! npm
[1]  v3.3.12
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! [email protected] lite: `lite-server`
[1] npm ERR! Exit status 3
[1] npm ERR!
[1] npm ERR! Failed at the [email protected] lite script 'lite-server'.
[1] npm ERR! Make sure you have the latest version of node.js and npm installed.

[1] npm ERR! If you do, this is most likely a problem with the ccm2-site package
,
[1] npm ERR! not with npm itself.
[1] npm ERR! Tell the author that this fails on your system:
[1] npm ERR!     lite-server
[1] npm ERR!
[1]  You can get their info via:
[1] npm ERR!     npm owner ls ccm2-site
[1] npm ERR! There is likely additional logging output above.
[1]
[1] npm ERR! Please include the following file with any support request:
[1] npm ERR!     D:\Projects\ccm2-site\npm-debug.log
[1] npm run lite exited with code 1
^CTerminate batch job (Y/N)? y

The above log is preceded by a lot of fast file servings for about or below 5ms.

A sample that shows how big (response ?) times are after I have changed one of my html files - usually serving these files takes less than 5ms but from the log file it is visible, that after the file change detection, service of really small (.css) files takes 5 seconds:

[1] 15.12.30 10:57:56 200 GET /app/configuration/language-and-font/language-and-
font.html (Unknown - 1ms)
[1] [BS] File changed: app\configuration\prices\prices.html
[1] [BS] File changed: app\configuration\prices\prices.html
[1] 15.12.30 11:41:02 200 GET /./index.html (Unknown - 852ms)
[1] 15.12.30 11:41:08 200 GET /assets/css/reset.css (Unknown - 4816ms)
[1] 15.12.30 11:41:08 200 GET /assets/css/style.css (Unknown - 4816ms)
[1] 15.12.30 11:41:08 200 GET /node_modules/systemjs/dist/system.js (Unknown - 4
816ms)
[1] 15.12.30 11:41:08 200 GET /node_modules/es6-shim/es6-shim.min.js (Unknown -
4817ms)
[1] 15.12.30 11:41:08 200 GET /node_modules/angular2/bundles/angular2-polyfills.
min.js (Unknown - 4818ms)
[1] 15.12.30 11:41:08 200 GET /node_modules/rxjs/bundles/Rx.min.js (Unknown - 48
22ms)
[1] 15.12.30 11:41:08 200 GET /node_modules/angular2/bundles/router.min.js (Unkn
own - 14ms)

My package.json scripts section is:

    "scripts": {
        "tsc": "tsc",
        "tsc:w": "tsc -w",
        "lite": "lite-server",
        "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
    },

And I'm starting everything with npm run start

My configuration is Chrome 47, Node 5.3.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.