Node js Tutorial – Setup Web Server in 3 Minutes with http-server Module
Articles,  Blog

Node js Tutorial – Setup Web Server in 3 Minutes with http-server Module

If you haven’t install Node.js yet, you can download it at Node.js website. (this tutorial assumed that you’re using Windows) pick any version that you’d like and proceed with the install wizard Next prepare a folder that you’ll be using as a web directory I’m going to create a new folder “webdir” Next, I’ll create a dummy index.html to test when after we started the server Next, open a command prompt and change directory to the upper level folder Then, we’ll use “npm init” to initialize to create a package.json You’ll be asked of several questions about the package info. We’ll skip that for this tutorial and go with the default value Next, we’ll use npm to install a http-server package http-server is a simple light weight http server package for Node.js To install, type “npm install http-server” npm will download http-server package from npm public registry (You’ll get a few warning, this because we didn’t fill in the package info when we did npm init. Just ignore it) After npm has finished, you’ll see node_modules and package.json in the folder Next, change cmd directory to the webdir folder (the folder that you’ll use as a web directory) We’re going to start the server by executing the http-server on Node.js Type in “node” follow by the path to http-server package inside node_modules/http-server/bin (You can drag the file to the cmd) Then hit enter Done! Your server is up and now listening at port 8080 You can also change the listening port to something else Hirt Ctrl+C to stop the server Start the server again with the same command follow by -p 80 Now your server is listening to port 80 which is the default HTTP port Thanks for watching! Don’t forget to like or subscribe 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *