The NodeSource Blog

Getting Started with Node.js and MongoDB

Since early on, MongoDB has been a simple choice for a database when building out a Node.js application. Because of how well they work together, the ecosystem evolved and we ended up with things like the MEAN stack, which has become one of the most popular stacks for Node.js.

Because of the long relationship Node.js and MongoDB have, there’s a lot out there that gets in the way of finding the useful information about how to use Node.js and MongoDB together for an application - be it kicking things off, deploying an app to the cloud, or monitoring and updating an app in production.

Today, I’ve gone through and collected some of the best resources that cover as much surface area as possible to get started with building and deploying apps Node.js and MongoDB.

Resources for MongoDB and Node.js:

Tools for MongoDB and Node.js:

  • The MongoDB Driver for Node.js is the officially maintained "driver" to bridge MongoDB and Node.js.

  • The Mongoose library for Node.js is the classic connector in the Node.js community for MongoDB. I started off trying to learn Node.js with it, and it’s still an excellent tool.

  • The learnyoumongo NodeSchool workshopper is a great hands-on tool that will get you up and runnin with MongoDB quickly.

  • The Helm Chart for deploying MongoDB into a Kubernetes Cluster. Since Kubernetes is becoming such an important tool for orchestrating Node.js apps, this is a fantastic resource.

  • The MongoDB Dockerfile, which can simplify local development when working with MongoDB. Zero setup other than getting it up and running with Docker, which is perfect if you’re also containerizing Node.js.

  • MongoDB’s Compass tool is built with Electron - meaning Node.js and Chromium under the hood of the desktop app.

  • Mongotron is an OSS electron client for managing MongoDB - great place to look at some code and learn about Node.js, MongoDB, and Electron at the same time.

The MongoDB and Node.js Stacks - MEAN and MERN

  • The MEAN repo, which has almost everything needed to get setup with MEAN apps

  • The MERN starter repo, which encapsulates some needed context and deps for MERN apps

A lot of the time, you can roll your own version of these stacks without needing the repos listed above. Here are the parts used in each:

  • MongoDB - to connect with Node.js, all you will need is the official MongoDB Driver or Mongoose.

  • Express - the web framework that will serve your MEAN/MERN web app.

  • Node.js - Node.js is, of course, the base programming platform that you’ll be working within both stacks.

  • Angular - the A in MEAN, Angular is the classic example and driver of the MEAN stack that helped out with full-stack dev with framework abstractions.

  • React - The R in MERN, React is pretty big with no signs of slowing down. The MERN stack is still relatively new, but I’m guessing it will grow in popularity in the long run with those that are looking to use MongoDB.

  • Webpack - Webpack can be used with either stack, and can help you deliver excellent experiences quickly with optimized bundles of your front-end resources.

  • Redux - Redux is part of the MERN stack as a part of the tooling surrounding React and statefulness. Use is not required, but it’s an excellent utility.

One last thing…

If you’re interested in MongoDB and Node.js, then you’ll probably be looking forward to the new features in Node.js 8. There are some pretty impressive improvements - ranging from performance to brand new features - that you’ll want to know.

That said, if you’re looking to take a deep dive into Node.js, or just want to drill down and squeeze every possible ounce of performance out of your apps, you should check out our Node.js Training and Architecture Evaluation offerings for teams and businesses.

Otherwise, you can stay in touch with what’s happening with Node.js, and it’s truly massive ecosystem, by checking out @NodeSource on Twitter - we’ll keep you up to date with the latest releases, tools, news, guides, and more.