Nodejs REST API to make requests to perform CRUD operations for book. API uses mongodb to persist data.
-
Docker needs to be installed and running on your machine. Please follow instructions on Docker Official Site.
-
Docker compose also needs to be installed. You can get it from Docker Official Site - Docker Compose Install.
-
You need to have
.envfile in root folder. File must have MONGO_URI to run and connect mongodb for traditional node app.
MONGO_URI='mongodb://localhost:your-port/your-mongo-db-name'
Default PORT: 27017
- You need to have
.env.devfile in root folder. File must have MONGO_URI to run and connect mongodb for dockerized app.
MONGO_URI='mongodb://mongo:your-port/your-mongo-db-name'
Default PORT: 27017
- To build images (It can take a while at the first place.)
docker-compose build --no-cache
- This will run the API on PORT 3000. Thanks to nodemon package, changes will be watched and immediately served.
docker-compose --env-file .env.dev up
** To stop the running API
docker-compose down
You can send requests to ;
- localhost:3000/book GET/PUT/POST/DELETE
To run REST API on your local machine, you need to install Node and MongoDB. You can install following these urls.
npm install
To run server
npm run start
Or run server and watch changes with nodemon
npm run start-watch
To run tests
npm run test
There is a folder in project named postman_requests. That folder has
- requests.postman_collection
- requests.postman_environment
files. You can import collection and environment file to test API with postman.