1#1. server.js
2var express = require('express');
3var app = express();
4
5app.get('/', function (req, res) {
6 res.status(200).send('Hello World!');
7});
8
9var port = process.env.PORT || 3000;
10
11var server = app.listen(port, function() {
12 console.log('Express server listening on port ' + port);
13});
14
15open cmd run server.js
16"node server.js"
17log:Express server listening on port 3000
18
19& then
20
21open link "http://localhost:3000/" in your browser and show result.
1using command line >>>
2
3npm init
4
5open text editor create a js file. for example like index.js and paste following code.
6
7>>>
8
9const http = require('http');
10
11const hostname = '127.0.0.1';
12const port = 3000;
13
14const server = http.createServer((req, res) => {
15 res.statusCode = 200;
16 res.setHeader('Content-Type', 'text/plain');
17 res.end('Hello World');
18});
19
20server.listen(port, hostname, () => {
21 console.log(`Server running at http://${hostname}:${port}/`);
22});
23
24----
25
26run using
27node app.js