How to CRUD with Node.js and MongoDB

MongoDB was one of the first NoSQL data stores, and it is the most popular NoSQL data store today. The Node.js JavaScript runtime continues to hold a dominate place in back-end development. Together they make a highly flexible and dynamic technology stack.

As you’ll see, Node.js and MongoDB allow you to quickly implement essential application functionality like CRUD (create, read, update, and delete) operations. In this article, we’ll take a look at the CRUD basics, using the latest Node.js MongoDB driver (version 3.6+).

Node.js and MongoDB setup

You’ll need Node.js and MongoDB installed on your system, and a command line with the curl command available. (If you’re using a Linux, MacOS, or Windows 10 version since 2018, you most likely have curl.)

You can download MongoDB for your OS here. Once downloaded, you can install it as a service or run it as an executable. Either way, ensure that MongoDB is running by opening a command line and running the mongo command. (You may need to add the command to your path if you didn’t install as a service.) This gives you access to the MongoDB instance running on your system.

Next, ensure that you have Node.js and npm installed. At the command line, type node -v. If Node.js is installed, you’ll get the version number. If not, go to the Node.js download page and install Node on your machine.

Curl allows you to perform simple HTTP requests from the command line. For example, if you run curl you’ll receive the markup from the Google main page.

Copyright © 2021 IDG Communications, Inc.

Source link