CRUD stands for Create, Read, Update and Delete. These are the basic operations almost every simple web app would be designed to achieve.
If you don’t have the idea about REST API, you can visit the below link and learn the basic about REST API. https://restfulapi.net
- You must have Node.js and MongoDB installed in your pc.
- Optionally you can install MongoDB Compass to manage MongoDB using GUI
- ExpressJS Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
- mongoose Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.
- body-parser Node.js body parsing middleware.Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
- Clone the project from github using the following command
git clone https://github.com/mdhelaluddin-ctg-bd/nodejs-mongodb-crud-api.git
- Enter to the project directory and Install node mudules
npm install
- Run index.js file
node index.js
There you go! You might wonder the below output in your terminal.
Node.js and MongoDB CRUD app is listening on port 3000!
You can install POSTMAN as chrome extension to test apis.
Create or Enter new product information to your databas table
Method : POST
URL : http://localhost:3000/products/create
Parameters : name, description, price
if you are using POSTMAN, set parameters from BODY > x-www-form-urlencoded
Get product information by ID
Method : GET
URL : http://localhost:3000/products/[PRODUCT-ID]
Update product information usding product id
Method : PUT
URL : http://localhost:3000/products/[PRODUCT-ID]
Parameters : name, description, price
if you are using POSTMAN, set parameters from BODY > x-www-form-urlencoded
DELETE product information by ID
Method : DELETE
URL : URL : http://localhost:3000/products/[PRODUCT-ID]
If you are still facing any problem feel free to contact with me at [email protected] or you may create issue. I will try to response back to you asap. Thanks.