
In NodeJS is Server side program. It similar to JavaScript, It will create the servers. These servers help to serve request based on our requirements.
In NodeJs we need to install required modules with help of npm(Node Package Manager). It will maintains packages that are helps to extend our functionality.
Example: first_program.js
var http = require("http"); var express = require('express'); var app = express(); // Running Server Details. var server = app.listen(8082, function () { var host = server.address().address var port = server.address().port console.log("Example app listening at %s:%s Port", host, port); }); app.get('/example', function (req, res) { res.send("Welcome to CodeExpertz Blog"); });
Executing :
// Goto the directory that first_program.js and run below command in command prompt or terminal. Drive://Path to Source file >node first_program.js Example app listening at :::8082 Port
Output:
Category: