Info 253a: Web Architecture
Kay Ashaolu
And that's it for installation!
sudo apt-get install nodejs
sudo apt-get install npm
npm init -y
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
npm install express --save
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.14.0"
}
}
app.js
var express = require('express'); // Adding the express library
var app = express(); // initializing applicaiton
// Define your routes here
app.get('/', function (req, res) {
res.send("<h1>Hello World</h1>");
});
// Start up server on port 3000 on host localhost
var server = app.listen(3000, function () {
console.log('Server on localhost listening on port 3000');
});
nodejs app.js
app.get('/', function (req, res) {
res.send("<h1>Hello World</h1>");
});