lehmannse / nodejs-express-rest

A backend project to create lightweight, fast, scalable REST APIs quickly and simply with unit testing.

Repository from Github https://github.comlehmannse/nodejs-express-restRepository from Github https://github.comlehmannse/nodejs-express-rest

RESTful Web Services with Node.js and Express

The goals for the project are

  • Get Data

    • Creating a Model
    • Implement HTTP GET
    • Wire up to MongoDB
    • List and search for items
  • Post Data

    • POST with Body Parser
    • Testing with Postman
    • Saving data
  • Updating Data

    • Implementing PUT
    • Middleware
    • Implementing PATCH

Stack ⚙️

  • Node.js
  • Express

Tooling 🔧

  • Nodemon
  • Eslint
  • Postman

On MongoDB 🍃

When using Windows, an important part to understand handling MongoDB is how to include the MongoDB binaries to the environment variables.

The procedure is explained on the installation guide but an interesting explanation on the legacy command 'mongo' is found here and was very useful in the development the project.

We create and populante the bookAPI database used on the project by doing mongosh bookAPI booksJson.js. To check it, we can enter mongosh and execute in the terminal

show dbs
use bookAPI

After that, we have switched to the bookAPI, we can see the collections using show collections and display the contents of it using db.books.find()

Important entries to understand the commands used are the Databases and Collections, listCollections and Collection Methods pages from MongoDB docs.

On Mongoose 🦦

According to a MongoDB developer article "Mongoose is a Node. js-based Object Data Modeling (ODM) library for MongoDB. It is akin to an Object Relational Mapper (ORM) such as SQLAlchemy for traditional SQL databases". So it is necessary to have MongoDB and Node.js installed.

It was used to created the Book model through the Schema defining the shape of the documents within the MongoDB collection.

An important page to understand the methods used throught the project as well as other data query possibilities is the Model page, with methods like create, find, findById, save, delete methods and many more.

About

A backend project to create lightweight, fast, scalable REST APIs quickly and simply with unit testing.


Languages

Language:JavaScript 100.0%