Mustache.js & Mongoose/MongoDB

Ethan Jarrell
Jul 20, 2017 · 2 min read

I made a recent blog post about how to create an API with mongo & mongoose. I recently started the process of building a front end application for the back end database. I found that when I started the process on the back end, I didn’t really have the user in mind. So when I started building the front end, I ended up making some adjustments to the back end, to give the user more options for viewing and using the application. I made this quick video explaining how some of those endpoints work, and how you can begin creating a front end application using Mustache.js. Mustache does have a bit of a learning curve, so I would recommend looking up the documentation on it.

The basic premise of mustache is that it has opening and closing tags, just like an HTML document. the opening tag looks like this: {{#text here}}, and the closing tag looks like this: {{/text here}}. Where I have the ‘text here’ text, you would actually put in your table name. You can see on the video, mine looks like this:

{{#activities}}

{{activity_name}}

{{/activities}}

When mustache reads that, it sees the activities, and it displays anything from the database in between the opening and closing activities tag. One of the fields in my table is ‘activity name’, and mustache would display that field. If I had 300 entries, it would display all 300 activity_name entries in the table. Mustache also gives other options for displaying, but because the system is ‘logicless’, it’s a little difficult to get used to.

This is a great resource on all of the mustache tags that are available to help get you started:

And here’s a link to the article on how to build the API:

)

Ethan Jarrell

Written by

https://www.linkedin.com/in/ethanjarrell/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade