Diving into nodejs api and mongodb

As a senior backend developer specializing in .NET, diving into the world of Node.js has been both exciting and challenging. I created a sample Node.js API using MongoDB, which is running on Docker. This project allowed me to explore Node.js and MongoDB, a NoSQL database type.

I aimed to structure the project as closely as possible to what I’m accustomed to with .NET projects. There are two ways to run this project: using native Node.js with ‘npm start’ or utilizing Docker Compose, which includes the MongoDB Docker image.

The project’s structure comprises three modules: Products, Orders, and User. The APIs for Products and User modules are protected with basic authorization, while the Orders API employs bearer authorization.

The Product API provides functionality for:

  • Retrieving a list of products
  • Getting a product by its ID
  • Creating, updating, and deleting products
    The Order API is straightforward, allowing the creation of an order with product ID and quantity. Lastly, the User API offers simple sign-up and login functionalities.

The Project structure as below:

node-rest-shop/
├─ node_modules/
├─ api/
│ ├─ controllers/
│ ├─ helper/
│ ├─ middleware/
│ ├─ models/
│ ├─ routes/

In addition, I’ve included a Postman collection in the project folder for your convenience. You can use it to try out the API and explore its functionality.

For those interested in exploring the project further, here is the GitHub repository link where you can check it out: https://github.com/kyawzaymoore/node-rest-shop

And as a side note, I’m also currently exploring Golang API development, so stay tuned for updates on my journey into this exciting domain!

Medium: https://kyawzaymoore.medium.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Up Next:

.NET docker image amd64 building on M1

.NET docker image amd64 building on M1