CRUD – create data
Now we're going to take what we've just learned, and use it to add the ability to create users in our application. If we look back to the routes we set up in app.js
, we can see that we have two routes for creating a user, the form itself and the form action.
app.get('/user/new', user.create); // Create new user form app.post('/user/new', user.doCreate); // Create new user action
Adding a new user form
To display the form in an HTML page, we need to do two things:
- Create the Jade template
- Link the template to the route
Adding the Jade template
By default Express will install with two Jade template files, layout.jade
and index.jade
. The layout template contains the HTML skeleton, including the DTD
, <head>
, and <body>
tags. The index ...
Get Mongoose for Application Development 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.