Create a CRUD App with Node and MongoDB: Lesson 13 of 17

Creating Events

Up Next

Showing Success Messages

Autoplaying in 7 seconds!

Cancel

We'll be creating a form that we can process using our Node/Express routes.

We need to bring in body-parser using:

npm install --save body-parser

Then we can use that in server.js with:

Table of Contents

    // grab it
    var bodyParser = require('body-parser');
    
    // configure it
    app.use(bodyParser.urlencoded({ extended: true }));

    For quick access, here's the content of the create event form:

    <form action="/events/create" method="POST">
    
        <div class="form-group">
            <label>Name</label>
            <input type="text" name="name" class="form-control">
        </div>
    
        <div class="form-group">
            <label>Description</label>
            <textarea name="description" rows="5" class="form-control"></textarea>
        </div>
    
        <div class="form-group">
            <button type="submit" class="btn btn-success btn-lg">Create</button>
        </div>
    
    </form>

    Chris Sevilleja

    173 posts

    Founder of Scotch.io. Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.