Skip to content

Instantly share code, notes, and snippets.

@yamikuronue
Created October 15, 2015 22:25
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 yamikuronue/622a92da64dba105d911 to your computer and use it in GitHub Desktop.
Save yamikuronue/622a92da64dba105d911 to your computer and use it in GitHub Desktop.
//Controller module
var express = require('express');
var router = express.Router();
app.route('/book')
.get(function(req, res) {
res.send('Get a random book');
})
.post(function(req, res) {
res.send('Add a book');
})
.put(function(req, res) {
res.send('Update the book');
});
module.exports = router;
//routs.js...?
const controller = {
getBooks: function(req, res) {
res.send('get a random book');
},
addBook: function(req, res) {
res.send('add a book')
},
updateBook: function(req, res) {
res.send('update book')
}
};
module.export = controller;
//route.js
const controller = require('./controller.js');
app.route('/book')
.get(function(req, res) {
controller.getBooks(req,res);
})
.post(function(req, res) {
controller.addBook(req,res);
})
.put(function(req, res) {
controller.updateBook(req,res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment