Creating REST API for movie using Node.js express framework.
- Create folder
config
in the root directory - Add file
database.js
inside the config directory - In the
database.js
file, add the url of the mongoose database connection similar as below (replace username, password and database name)
const DATABASECONNECTION = "mongodb+srv://<username:password>@cluster0.atx9j.mongodb.net/<database-name>?retryWrites=true&w=majority"
module.exports = { DATABASECONNECTION }
- Run
npm install
andnpm start
or usenpm run dev
(to start with nodemon)
- Build docker image:
docker build --tag name-of-the-app .
- Run the app with docker:
docker run -it -p 3000:3000 name-of-the-app
(map the available port in local machine to docker machine: 3000:3000)
- Navigate to your browser and go to: http://localhost:3000/api-docs to see the API document
- Run
npm test
- In the project folder, there is movie collection ready to import to the MongoDB database
- Also, Postman collection