Monday, August 22, 2016

The easiest way to start your Local Webserver with Node.js

On client-side development, it's often needed to quickly check or prove some script behavior in separate environment, so it's always good to have an extremely fast way yo launch your index.html on local web server.

npm http-server

http-server is a simple, zero-configuration command-line http server. It is powerful enough for production usage, but it's simple and hackable enough to be used for testing, local development, and learning.

Installing globally

Instalation via npm:

npm install http-server -g

This will install http-server globally, so that it may be run from the command line.


Run from command line

Add the following script into your project.json file:

"scripts": {
    "start": "http-server -a localhost -p 8000"
}

That's it, run from command line in your project root:

npm start

If everything went fine, you'll see the following output:

Starting up http-server, serving ./
Available on:
  http://localhost:8000
Hit CTRL-C to stop the server...

Miscellaneous

It's not possible to specify dependencies as "global" from a package.json. So, you could automate it and have http-server installed through preinstall script.

preinstall: Run BEFORE the package is installed.

So, following line in scripts might help ya:

"preinstall": "npm install http-server -g"

see Also


1 comment:

  1. A writer should always try to keep its writing very simple and clear. Always use facts which are easily acceptable by general people because they are very close to their assumptions and they welcome such kind of facts.cursus website bouwen amsterdam

    ReplyDelete