NodeJS_Mongo_BoilerPlate icon indicating copy to clipboard operation
NodeJS_Mongo_BoilerPlate copied to clipboard

CRUD Blog using NodeJS,Express, MongoDB

trafficstars

NodeJS Mongo BoilerPlate

CRUD API using NodeJS, Experss, MongoDB

About

This Repo is for beginners of NodeJS who wants to make a full API service. This repo has a good folder structure. Joi for validation of incoming data. Passport for encrypting passwords.

Prerequisites

Following are the softwares requried to get this api up and running.

Installing

  • Getting the configuration ready
    Copy the .env.example file at the same location and save as .env

    cp .env.example .env
    
  • Create account on MongoDB Atlas and paste the database URL in .env file

  • Create account on Sentry and paste the Sentry DNS into .env file (Only for production to get emails about errors)

  • Install the packages mentioned in package.json file for getting all dependencies of the project.

    npm install --save
    
  • Starting the application

    npm start
    

Getting started with the project with Docker

  • Fork the repository on GitHub.

  • Navigate to the folder of the repository.

  • To run this project, you should have Docker installed on your system. If you don't have Docker, you can visit The official site of Docker to install them on your system.

  • Building the Docker Image for Docker Hub

    ocker build -t your_dockerhub_username/your_project_name .
    

    The . specifies that the build context is the current directory.

  • It will take a minute or two to build the image. Once it is complete, check your images:

    ocker images
    

    You will see the image listed in the list.

  • Run the following command to build the container:

    ocker run -p 5000:5000 <your_dockerhub_username>/<your_project_name>
    

    All requests of port 5000 will be forwarded to port 5000 of container

  • Once your container is up and running, you can inspect a list of your running containers with following command:

    ocker ps
    

    You will see the image listed in the list.

  • With your container running, you can now visit your application by navigating your browser to http://your_server_ip. You will see your application landing page once again:

  • For stoping the container you can use following command:

    ocker stop <Container_Id>
    

Developers