Friday, 6 April 2018

NODE.JS Basic

Create a Node.js file named "myfirst.js" using notepad or IDE

var http = require('http'); //this is module 
http.createServer(function (req, res) { 
res.writeHead(200, {'Content-Type': 'text/html'}); 
 res.end('Hello World!'); }).listen(8080);

This will show result at http://localhost:8080  by call the Node using CMD.exe or terminal
type on your cmd/terminal
node myfirst.js 
and open http://localhost:8080

Ref > https://www.w3schools.com/nodejs/nodejs_get_started.asp


Next! Create module

Save module code below as myfirstmodule.js -

exports.myDateTime = function () {     
return Date(); 
};

Now lets call the module by create other .js file by copy this code


var http = require('http'); 
 var dt = require('./myfirstmodule'); // this is how to call the module above.

http.createServer(function (req, res) {     
res.writeHead(200, {'Content-Type': 'text/html'
});     
res.write("The date and time are currently: " + dt.myDateTime());     
res.end(); }).listen(8080);

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...