Adding a new note – create

Now, let's look at creating notes. Because the application doesn't have a route configured for the /notes/add URL, we must add one. To do that, we need a controller for the notes.

In app.js, make the following changes.

Comment out these lines:

// var users = require('./routes/users'); 
.. 
// app.use('/users', users); 

At this stage, the Notes application does not support users, and these routes are not required. That will change in a future chapter.

What we really need to do is add code for the notes controller:

// const users = require('./routes/users'); 
const notes  = require('./routes/notes'); 
.. 
// app.use('/users', users); 
app.use('/notes', notes); 

Now, we'll add a Controller module containing the notes router. ...

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.