Thameera Senanayaka
Allion Technologies
console.log('Hello world!');
app.js
$ node app.js
Hello world!
$
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200);
res.end('Hello World!');
}).listen(8000);
console.log('Listening on port 8000');
var results = db.query('select * from person');
process(results);
// more code
db.query('select * from person', function(results) {
process(results);
});
// more code
Non-blocking
Blocking
$ npm install express
var express = require('express');
app.js
NPM modules
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(8000, function () {
console.log('Listening on port 8000');
});
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.get('/user', function(req, res) {
/* */
});
app.post('/user', function(req, res) {
/* */
});
var server = app.listen(8000, function () {
console.log('Listening on port 8000');
});