Posts

Showing posts from September, 2022

How to using html page in nodejs code

 var http = require('http'),     fs = require('fs'); fs.readFile('./index.html', function (err, html) {     if (err) {         throw err;      }            http.createServer(function(request, response) {           response.writeHeader(200, {"Content-Type": "text/html"});           response.write(html);           response.end();       }).listen(8000); });

How to create a node JS start server

Step1 Install Node js 13 version download Step 2 Type this code in notepad and save file name as hello.js var http = require("http"); http.createServer(function (request, response) {    // Send the HTTP header     // HTTP Status: 200 : OK    // Content Type: text/plain    response.writeHead(200, {'Content-Type': 'text/plain'});      // Send the response body as "Hello World"    response.end('Hello World\n'); }).listen(8081); // Console will print the message console.log('Server running at http://127.0.0.1:8081/');  Step 3 Go to cmd box The  extension Saved file node hello.js