Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 571 Bytes

section42.1.md

File metadata and controls

36 lines (27 loc) · 571 Bytes

Section 42.1: Web Server Frameworks

  • Express
let express = require('express');
let app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});
  • Koa
let koa = require('koa');
let app = koa();

app.use(function *(next){
  let start = new Date;
  yield next;
  let ms = new Date - start;
  console.log('%s %s - %s', this.method, this.url, ms);
});

app.use(function *(){
  this.body = 'Hello World';
});

app.listen(3000);