Skip to content

nermin99/rest-api-example

Repository files navigation

REST API Example

With Node.js + Express, MongoDB & Docker

Setup

Prerequisites

Install Node and Docker on your machine.

Installation

Copy the environment:

cp .env.example .env

Install the dependencies:

npm install

Quickstart

docker-compose up -d mongo
npm run db:seed
npm run start:watch

Start

To start the backend:

npm start

To start the backend and listen for changes (recommended):

npm run start:watch

There is also option to load a sample dataset (aka seed) into the databse beforehand:

npm run db:seed

If you want to clear the database (perhaps before seeding?):

npm run db:purge

Stop

To stop the docker containers:

docker-compose down

To stop the docker containers and remove the data(i.e. the saved database):

docker-compose down -v

Testing

How to check if it works?

You can use something like Postman, to send http requests.

Else if you use VSCode, the REST Client plugin can be handy (see the request.rest file).

You can issue a GET request to the root endpoint to get all the endpoint categories that the REST API supports:

http://localhost:3000/api/v1

The request.rest file also contains some examples of requests you can make.

Optional: Register Mongo Database

If you want, you can use an online database instead of the local one.

  1. Register, create a free project, cluster and then a database on Mongo's website.
  2. Once it's up, copy the connection string.
  3. Paste the connection string in the .env file and uncomment the line.

About

A template/example of a RESTful API project with Node.js & Express

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •