How to create a local Server 10 lines of Express


Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.


First you need to make a directory to hold your server files and make it your working directory, assuming you’ve already installed Node.js.


Second you need to initialize a package.json file for your application by using the npm init command check package.json for more information.

This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:
If you want it to be a default file name, hit RETURN to accept the suggested default file name.

Third install Express in the server-app directory and save it in the dependencies list.

To install Express temporarily and not add it to the dependencies list, omit the --save option

Now inside of the main file that we created earlier we will start working on making an Express server by requiring express and invoking it.

Now we need to use the GET method so when a request is made to the root URL (/) we will respond with a message.
Here we are responding with “Hello World” message whenever a request is made to the root URL(/)

Here we need to make our app listen to port 3000 so the server can make a connection and start.
The callback will fire every time the server is running or restarted and here we made it to log a message for which port we are running the app on

Last we need to run the node on app.js command to start our server

Then, load http://localhost:3000/ in a browser to see the output.


That’s it people we are done and we have a running server uh oh 7 lines. Now lets get this app out in the wild, out onto the Internet quickly with Heroku.