i

Creating Hello World application

Before creating the first application, let's see the components of the Node.js application.

1. Importing Modules

2. Create a server (if the application needs to be called from the browser)

3. Read the requests and return the response accordingly.

Creating Hello World

Open Code Editor and type code as mentioned below

 Let us try and understand what each line means?

 Const http=require(‘http’)

  Imports the module to our file. Existing features of the module are imparted in the file.

  As we created the server using

  http.createServer(function()….)

  if none of it makes sense as of now, we will discuss in the coming sections.

1. Save it as hello-world.js and open the terminal (and reach to the destination where hello-world.js is stored) using
node hello-world.js

2. Open the browser and enter URL

http://localhost:5050/

 

5050 PORT is used because we gave that as the PORT number in hello-world.js file, and we can choose any number for this.