Slip 10

 Write node js script to build Your Own Node.js Module. Use require (‘http’) module is a built in


Node module that invokes the functionality of the HTTP library to create a local server. Also use the

export statement to make functions in your module available externally. Create a new text file to

contain the functions in your module called, “modules.js” and add this function to return today’s date

and time.

modules.js

// datetime_app.js


function datetime() {

    let dt = new Date();


    let date = ("0" + dt.getDate()).slice(-2);

    let month = ("0" + (dt.getMonth() + 1)).slice(-2);

    let year = dt.getFullYear();


    let hours = ("0" + dt.getHours()).slice(-2);

    let minutes = ("0" + dt.getMinutes()).slice(-2);

    let seconds = ("0" + dt.getSeconds()).slice(-2);


    let output = year + "-" + month + "-" + date +

                 " " + hours + ":" + minutes + ":" + seconds;


    return output;

}

module.exports = {datetime}



slip10.js

var http = require('http');

var dt = require('./modules');

var server = http.createServer(function(req,res){

res.writeHead(200,{'content-type':'text/html'});

const result = dt.datetime();

res.write('current date and time is ');

res.write(result);

res.end();

});

server.listen(1234);


Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.