1var http = require('http'); // Import Node.js core module
2
3var server = http.createServer(function (req, res) { //create web server
4 if (req.url == '/') { //check the URL of the current request
5
6 // set response header
7 res.writeHead(200, { 'Content-Type': 'text/html' });
8
9 // set response content
10 res.write('<html><body><p>This is home Page.</p></body></html>');
11 res.end();
12
13 }
14 else if (req.url == "/student") {
15
16 res.writeHead(200, { 'Content-Type': 'text/html' });
17 res.write('<html><body><p>This is student Page.</p></body></html>');
18 res.end();
19
20 }
21 else if (req.url == "/admin") {
22
23 res.writeHead(200, { 'Content-Type': 'text/html' });
24 res.write('<html><body><p>This is admin Page.</p></body></html>');
25 res.end();
26
27 }
28 else
29 res.end('Invalid Request!');
30
31});
32
33server.listen(5000); //6 - listen for any incoming requests
34
35console.log('Node.js web server at port 5000 is running..')
36