Showing posts with label node js. Show all posts
Showing posts with label node js. Show all posts

Thursday, 22 February 2018

How to Create Server in Node js

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
Simple As it is .

We have to give Host Name and port number , and rest is the server code , that is

http.createServer(req, res)
server.listen(port, hostname) .

Wednesday, 21 February 2018

Tuesday, 20 February 2018