This sample project explains how to create REST API using node.js with mongoDB. ๐
Create .env
file in the root directory.
Add the mongoDB connection URI as DB_URI
as follows.
DB_URI=<your url goes here>
Then install the dependencies.
npm install
This command executes with nodemon.
npm run dev
Fetch all books
GET /books
Fetch a book
GET /books/:bookId
Add a book
POST /books
{
"rating": 4.9,
"name": "The Hobbit X",
"category": "Action",
"bookId": "OLKA-1"
}
Update a book
PUT /books/:bookId
{
"rating": 4.6
}
Delete a book
DELETE /books/:bookId
Fetch top books
GET /books/top
Developed with ๐งก by Dhanushka