First try with Express

// Display list of all Books.
exports.book_list = function(req, res, next) {
Book.find({}, ‘title author’)
.populate(‘author’)
.exec(function (err, list_books) {
if (err) { return next(err); }
//Successful, so render
res.render(‘book_list’, { title: ‘Book List’, book_list: list_books });
});

};
module.exports = {
getList: async (req, res, next) => {
try {
const bookInstanceList = await BookInstance.find({})
.populate(‘book’)
.exec();
res.render(‘bookInstanceList’, {
title: ‘Book Instance List’,
bookInstanceList,
});
} catch (err) {
next(err);
}
},
}
const config = require(‘./common/config’);
const mongo = require(‘./loaders/mongo’);
const redis = require(‘./loaders/redis’);
const app = require(‘./loaders/express’);
app.listen(config.port, () =>
console.log(`App listening on port ${config.port}`),
);
// now.json
{
“version”: 2,
“name”: “learn-express”,
“builds”: [{ “src”: “/api/*.js”, “use”: “@now/node” }],
“routes”: [
{ “src”: “/catalog”, “dest”: “/api/catalog.js” },
{ “src”: “/catalog(/.*)”, “dest”: “/api/catalog.js” },
{ “src”: “/user(/.*)”, “dest”: “/api/user.js” },
{ “src”: “(/.*)”, “dest”: “/api/home.js” }
],
}
// api/catalog.js
const app = require(‘./setup’);
const catalogRouter = require(‘../routes/catalogRoute’);
const authMiddleware = require(‘../middlewares/authMiddleware’);
app.use(
‘/catalog’,
authMiddleware.validateToken,
authMiddleware.refreshToken,
catalogRouter,
);
app.use(‘*’, (req, res) => {
res.status(404).send(‘Page not found!’);
});
module.exports = app;

--

--

--

From translator -> Manual QC Engineer -> Automation QA Engineer -> NodeJS Developer -> yearning to learn more

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hung Tran Nguyen

Hung Tran Nguyen

From translator -> Manual QC Engineer -> Automation QA Engineer -> NodeJS Developer -> yearning to learn more

More from Medium

Sequelize ORM in our Final Project

How To Make Your NodeJS Application Secure?

Axios, login & cookies when the server returns 303

Beginning with KoaJS and Creating Server using Koa