Create a CRUD App with Node and MongoDB

All Events

Creating a list of events will be straightforward. This will mirror how we'll get information from our MongoDB database in the future.

const events = [
  { name: 'Basketball', slug: 'basketball', description: 'Throwing into a basket.' },
  { name: 'Swimming', slug: 'swimming', description: 'Michael Phelps is the fast fish.' },
  { name: 'Weightlifting', slug: 'weightlifting', description: 'Lifting heavy things up' }

To loop over these and show them in the browser, we'll pass these to ejs and show them:

// return a view with data
res.render('pages/events', { events: events });

And in our view:

<% for (var event of events) { %>
        <td><%= %></td>
        <td><%= event.description %></td>
            <a href="/events/<%= event.slug %>" class="btn btn-sm btn-primary">View</a>
<% } %>

Like this article? Follow @chrisoncode on Twitter