Steps to Create Node Application (Web-Based)

Step 1: Import required modules

Load Node modules using the required directive. Load the http module and store the returned HTTP instance into a variable.

Syntax:

var http = require("http");

Step 2: Creating a server in Node

Create a server to listen to the client’s requests. Create a server instance using the createServer() method. Bind the server to port 8080 using the listen method associated with the server instance.

Syntax:

http.createServer().listen(8080);

Step 3: Read request and return response in Node:

Read the client request made using the browser or console and return the response. A function with request and response parameters is used to read client requests and return responses.

Syntax:

http.createServer(function (request, response) {...}).listen(8080);

Node First Application

Node is an open-source, cross-platform server environment that executes JavaScript using the V8 JavaScript Engine. Node helps to write front-end and back-end code in the same language. It helps to write efficient code for real-time applications.

As a beginner in development, most developers find it difficult to create their first Node.js Application. In this article, we will help you in building Node applications.

We will discuss the following two approaches to create our first application in Node:

  • Creating Console-based Node Application
  • Creating Web-based Node Application

Similar Reads

Creating Console-based Node Application

The Node console-based applications are run using the Node command prompt. The console module in Node.js provides a simple debugging console. Node is a global console that can be used for synchronous as well as asynchronous communication....

Creating Web-based Node Application

...

Steps to Create Node Application (Web-Based)

...

First Node Application

A web-based Node application consists of the following three important components:...

Step to Run Node Application:

Step 1: Import required modules...