14 Program to Manual Routing in NodeJS

Program:

var http = require('http');

var fs = require('fs');



var server = http.createServer(function (request, response) {

    if (request.url == '/home' | request.url == '/') {

        response.writeHead(200, {

            'Content-Type': 'text/plain'

        });



        response.end("Homi Man");

    } else if (request.url == '/profile') {

        response.writeHead(200, {

            'Content-Type': 'text/plain'

        });



        response.end("Profile Page");



    } else {

        response.writeHead(200, {

            'Content-Type': 'text/plain'

        });



        response.end("404 Error Not Found");

    }

});



server.listen(3000, '127.0.0.1');


Output:

Manual Routing in NodeJS

Previous
Next Post »