Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Mar 23, 2015
0 parents commit 769501e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "writing-express-middleware",
"version": "0.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.12.3"
}
}
33 changes: 33 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var express = require('express');

var app = express();

function logger(req,res,next){
console.log(new Date(), req.method, req.url);
next();
}

function hello(req,res,next){
res.write('Hello \n');
next();
}

function bye(req,res,next){
res.write('Bye \n');
res.end();
}

var apiRouter = express.Router();

apiRouter.use(logger);

// app.use(hello,bye);

app.use('/api',apiRouter);

app.use(hello,bye);

var server = app.listen(3000);

0 comments on commit 769501e

Please sign in to comment.