April 4, 2019
2 min read
Sometimes when you're developing a application it can be helpful to run your project on a web server. Often running that server on your local machine is easier and faster during development. It lets you avoid uploading your work in progress files and setting up a complex build system.
From their documentation page:
http-serveris 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.
This link will instruct you on how to get up and running with Node.js and NPM.
Verify you've got both installed correctly by running the following commands in my terminal.
To install the package globally, using Node Package Manager (npm), run the following command in your terminal:
npm install -g http-server
To use the web server, navigate to the directory that you wish to host a server in. Then run the following command:
This will host a web server at the address echoed into your terminal. Copy and paste that URL into your browser to view it.
There are several helpful options you can use with http-server. We'll use the following couple:
-sThe silent flag will suppress log messages from output. This hides all the noisy debug messages you saw in your terminal.
-oThis flag will open your web browser to the appropriate URL after the server starts running.
Our final command: