O'Reilly logo

Mongoose for Application Development by Simon Holmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required