There are a lot of use cases for Node.js but it shouldn't be used for every task you think of. It's not something you'd want to use for CPU-Intensive operations as this will annul most of it's advantages and there are far better alternatives. You should always pick the best tool for the job rather than a new cool tool or the tool you're best as using. The use cases where Node has really become one go tos is for building fast, scalable network applicaitons. Looking at the RisingStack's blog overview of Node.js in 2015 you can see that it's being used a lot for creating REST APIs, real-time services, microservices and tooling.
With that brief summary lets take a look at building a HTTP server with Node.js.
To install Node.js if you don't already have it simply go to the Node.js website and get the installer.
For the simple HTTP server you'll need three files: index.html, package.json and server.js. Put these all in the same directory.
The index.html file will be the file we are going to serve up.
package.json defines the name of our node app and the file that will be run.
Our server.js file with plain node.js.
In your terminal navigate to the directory you created the files in and type in
Now you can navigate to localhost:2000 and see the server in action! Now that was nice and easy, but it gets even easier with the popular minimalist framework express.
To install express simply
Now for our express server. In server.js go ahead and replace all the code with
Go ahead and
Then refresh localhost:2000 and that's all there is to making a HTTP server with express.