September 2018
Intermediate to advanced
328 pages
9h 10m
English
The assign-routes.js file defines routes and adds them to the express instance (app) created in index.js. In Express, routes can be defined directly on app (for example, app.get()), or through the use of a Router. In this case, a Router was used to add multiple methods to the same route path. The following code, taken from the assign-routes.js file, creates a Router instance and adds two routes: a GET route that returns all transactions, and a POST route that creates a new transaction:
module.exports = function assignRoutes(app, assets) { const { db, wasmInstance } = assets; const transaction = new Transaction(db, wasmInstance); const transactionsRouter = express.Router(); transactionsRouter .route('/') ...Read now
Unlock full access