With Node.js + Express, MongoDB & Docker
Install Node and Docker on your machine.
Copy the environment:
cp .env.example .env
Install the dependencies:
npm install
docker-compose up -d mongo
npm run db:seed
npm run start:watch
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
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
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.
If you want, you can use an online database instead of the local one.
- Register, create a free project, cluster and then a database on Mongo's website.
- Once it's up, copy the connection string.
- Paste the connection string in the .env file and uncomment the line.