Skip to content

Instantly share code, notes, and snippets.

@VivienAdnot
Last active July 31, 2018 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VivienAdnot/e3cf44de745531c6cca7be5de53c341a to your computer and use it in GitHub Desktop.
Save VivienAdnot/e3cf44de745531c6cca7be5de53c341a to your computer and use it in GitHub Desktop.
node-express poc express.Router
import express from 'express';
import routes from './routes';
const app = express();
app.use('/', routes);
app.use((req, res) => {
res.status(200).send(res.data);
});
app.use((err, req, res, next) => {
console.log('error mw reached');
res.status(500);
res.end();
});
app.listen(8008);
import express from 'express';
const routes = express.Router();
routes.get('/ok', (req, res, next) => {
res.data = {
result: 'ok'
};
next();
});
routes.get('/nook', (req, res, next) => {
next(new Error('test error'));
});
export default routes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment