How To Create Node Server
javascriptNodeserver
Sep 10, 2022

In this article we discuss how to create js node server

First, Open a terminal and create a new project directory named node-server


mkdir node-server

then enter the node-server directory

second, create a new file named app.js


type nul > app.js

Then write the require code of app.js for create node server

app.js

var http = require('http');
var server = http.createServer(function (req, res) {
res.write('Hello World!');
res.end();
});
server.listen(5000);
console.log('Node.js web server at port 5000 is running..')

To run this command app.js


node app.js

output:

console

Node.js web server at port 5000 is running..

Explanation

Tip
  • For better view use large screen
  • Click every step

👆 step 1: Import Node.js core module

step 2: creating server

step 3: handle incomming requests here..

step 4: listen for any incoming requests

step 5: console log

Output

app.js

var http = require('http');
var server = http.createServer(function (req, res) {
res.write('Hello World!');
res.end();
});
server.listen(5000);
console.log('Node.js web server at port 5000 is running..')

Thanks

← Back

2022 © Rahat Hosen