Thursday, 3 October 2019

Show Webpage

Hi All,

User the following steps

1. Create Server.js

var http = require('http');
var url = require('url');
var fs = require('fs');

http.createServer(function (reqres) {
  var q = url.parse(req.urltrue);
  var filename = "." + q.pathname;
  fs.readFile(filenamefunction(errdata) {
    if (err) {
      res.writeHead(404, {'Content-Type': 'text/html'});
      return res.end("404 Not Found");
    } 
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080);

2. Create webpage

<!DOCTYPE html>
<html>
<body>
<h1>Winter</h1>
<p>I love the Rose!</p>
</body>
</html>

3: run using

localhost:8080/hupwriter.html

Wednesday, 2 October 2019

Create a Server for Node JS Programs

Hi All,

Use this code


----------------------------------------------
1. Create server.js

var http=require("http")
var server=http.createServer(function(request,response)
{
    response.writeHead(200,{'Conent-Type':'text/plain'});
    response.end('Hello World\n');
})

server.listen(8081);
console.log('Server running at http://127.0.0.1:8081');


2. Go to Terminal in VS code and write this code

D:\HUPNode>node server.js

3. You will get the output

Server running at http://127.0.0.1:8081

4. Go to browser and type

 http://127.0.0.1:8081

You will get the output as


Introduction

Hi All,

Welcome to the world of Node JS

---------------------------------------------

Follow the steps to start with

1. Download Node JS from https://nodejs.org/en/download/

For running Node JS programs

2. Download VS Code from https://code.visualstudio.com/Download#

for creating programs in an easier manner

3. Create a folder  in your hard disk

Eg : D:\HUPNODE

4. Verify the installation

Eg : D:\HUPNODE>npm -v

5. Configure package.json

Eg : D:\HUPNODE>npm init -y