Getting started with Node.js

Take Your First Step Into A Larger World

To Begin Again

Setting Up The Server

First, create a new .js file and copy this code into it.

The first line is an example of a Node.js module. Modules are basically JS libraries that come built-in to Node. To use a module you must use the require() function along with the name of the desired module. When we require ‘http’, the application now has access to the http module which allows us to create our server.

Lines 3 through 6 calls the createServer() function on the http module variable declared above. We want to establish what our response will be for our app. As long as the response code is 200, we can access our app whose content type has been defined (text/html) and what the actual content will be (“This is my new Node App.”). The last line dictates what port to listen for (8080).

Running the Code

Now our file has been initialized. Navigate to the specified port (8080) and you will see the content of the app. In this case its simple text.

Look how pretty our app is already

Simple But Effective

I love traveling, music, and movies.