Tuesday, 2 July 2019

How to Create server in node js


step1: Create one folder nodeserver > install package.json 
step2: Create new file index.js ==> in index.js type the following code

const http = require('http');
const hostname ="localhost"';
const port = 3000;
const server = http.createServer((req,res) => {
   console.log(req.headers);
   res.statusCode = 200;
   res.setHeader('Content-Type','text/html');
   res.end('<html><body><h1> Server Connect </h1></body></html>');   

});
server.listen(port,hostname,() ==> {
console.log(`server running at http://${hostname}:${port}');
});


Step 3 : Add script "start" :"node index";


Step 4 :  Run the server in commandprompt

Output 

Step 5 : Check in Webbrowser 


No comments:

Post a Comment

SEO introduction

What is SEO? SEO(Search Engine Optimization ) is a technique that helps to bring the Website on top. Seo depends on the Keyword . Ke...