Adding messages to the Notes router

Now that we can store messages in the database, let's integrate this into the Notes router module.

In routes/notes.mjs, add this to the import statements:

import * as messages from '../models/messages-sequelize'; 

If you wish to implement a different data storage model for messages, you'll need to change this import statement. You should consider using an environment variable to specify the module name, as we've done elsewhere:

// Save incoming message to message pool, then broadcast it router.post('/make-comment', ensureAuthenticated, async (req, res, next) => {     try {        await messages.postMessage(req.body.from,             req.body.namespace, req.body.message);        res.status(200).json({ });    } catch(err) { res.status(500).end(err.stack); ...

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.