Skip to content

extrawest/express-js-mongoose-crud

Repository files navigation

Express JS / MongoDB CRUD app

Maintenance status Maintained by License Release version

Overview

The app showcases core structure of Express backend applications with custom decorators for route handling, data validation and interaction with MongoDB databases.

Prerequisites

MongoDB cluster is required to run the application. Follow instructions at https://www.mongodb.com/cloud/atlas/register to obtain a free MongoDB Atlas database to test the app.

Once the cluster is created, press "Connect" on the Clusters dashboard to obtain connection parameters: Clusters dashboard with Connect button

When prompted, select "Drivers" to view connection parameters to your cluster: Select method of connection to Cluster

These connection parameters will be required for environment setup later.

Installation:

  1. Clone this repository:

    git clone
  2. Navigate to the folder containing the code:

    cd <folder_name>
  3. Install dependencies

    npm i
  4. Copy env file

    cp .env.example .env
  5. Set up the environment constants

    SERVER_PORT=3000
    SERVER_HOST="localhost"
    
    MONGO_USER="username to access your MongoDB Cluster"
    MONGO_PASSWORD="password to access your MongoDB Cluster"
    MONGO_URL="URL of your MongoDB Cluster"
    MONGO_APP_NAME="MongoDB Cluster name"
    
  6. Run the application:

    nodemon

Interact with the app

The app is designed for interaction over HTTP. Any tool for API testing is compatible with the app. Postman is reccommended.

API structure:

OPTIONS request with any path responds with a list of supported request options


GET /books/get/all - Responds with a list of books currently stored in MongoDB


GET /books/get/:id - If a document with id parameter is present, returns a Book object with matching ID


POST /books/create - creates a Book object in MongoDB with specified content. Request body is required:

{
    "title": "BookTitle", // { type: String, required: true, unique: true },
    "author": "BookAuthor" // { type: String, required: true },
}

POST /books/query - Returns a list of Book objects currently stored in MongoDB matching specified filters. Filters are specified in request body:

{
    "title": "BookTitle", // { type: String, required: false },
    "author": "BookAuthor" // { type: String, required: false },
}

PUT /books/update/:id - If present, updates a Book object in MongoDB matching the id parameter with content specified in request body:

{
    "title": "BookTitle", // { type: String, required: true, unique: true },
    "author": "BookAuthor" // { type: String, required: true },
}

DELETE /books/delete/:id - If present, deletes a Book object from MongoDB matching the id parameter


License

This project is licensed under the BSD-3-Clause License - see the LICENSE for details

Created by Serhii Ovchar
© Extrawest, 2026

About

The app showcases core structure of Express backend applications with custom decorators for route handling, data validation and interaction with MongoDB databases.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors