How to Increase Performance of any Node.js project using MongoDB
Tags: javascript, node, showdev, productivity
Published: 2021-12-02 04:53:24

Hello Developers! I hope your development is going smoother. Today, In this blog we are discussing the Performance of an application.

![Source: [makeuseof.com](https://www.makeuseof.com/tag/people-contribute-open-source-projects/)](https://cdn-images-1.medium.com/max/2400/0*idLccXbryz5rzpnU)

Every Backend Developer knows, Whenever Backend development starts, one thing that must be focused on is the performance of a project that has a huge amount of code and database calls. A developer whether one is a newbie or not must be most concerned about whether one’s code is runnable as well as efficient.

After having a discussion with many developers, one thing everyone felt was, When a project starts it has fewer requirements and modules, which will later increase and the project, Database, and code become a mess.

Writing a runnable code is not an uphill battle for a Developer. Writing a code that is efficient and runnable is what takes a lot of thinking and research. Nobody wants to see a page that takes more than 2 seconds to refresh or process.

* Here are 3 ways a Developer should consider in a Software development cycle

 1. Project Architecture

 2. Modular coding

 3. Database Design and queries

## Project Architecture

A good start is a half Battle. Privileging a Project with its structure practically is indeed the hardest yet delicate process. I will lay out some basic points that must cross your mind before selecting an architecture for your project.

* Following a Model-View-Controller Architecture

* Adding a Service and Validation Layer

* Using a Dependency Injection

* Separate Business Logic and API routes

* Separate Layer for third party calls

* Comments

* Use a Linter

* Follow a Style guide (eg. Airbnb)

* Use of Config folder for the configuration files

* Exception Handling

## Modular Coding

Separation of concerns while writing a code is the basis of modular coding. Defining common code in the function and using it as a dependency in other files, so when any change occurs, you need to make changes in one place and the change reflects everywhere, which saves time.

Apart from common functions, using Third-party APIs in a project and separation of their functionality is a best practice.

## Database Design and queries

A well-designed database uses simpler queries and fast execution. Overall performance of any software depends on the Database Design. Inaccurate database design leads to regular changes in the database and in the code which at the end leads to lower and inefficient performance.

Adding Indexes while Designing a database leads to faster performance. Indexes in Collections serve faster data. There are several types of indexes available for MongoDB that you can learn and apply to your Database schema. Here’s the link: [https://docs.mongodb.com/manual/indexes/](https://docs.mongodb.com/manual/indexes/)

The use of ORMs /ODMs like mongoose that gives you more functionalities like managing relationships, Datatype validations, hooks, etc., lets you make more efficient and secure use of MongoDB.

After Designing a Database, Using features like aggregation and Custom queries that simplify logic as manipulating the Data is a very important part of a development cycle.

## Conclusion

In a nutshell, If you are starting a new project and your choice of technologies are node.js and MongoDB, I have great news for you. There is a new exciting SaaS platform available called [DhiWise](https://hubs.la/H0_-wmC0) where you just need to add your Database schema (You can add hooks and index too!!! ) and boom💥 in a few clicks your project will be generated. You can add custom routes as well as query builders for routes. They are providing two project architectures- MVC and Clean-code-MVC along with mongoose ODM that lets you make your project more efficient and faster and covers all the points mentioned above.

Also, You can find me on [LinkedIn](http://www.linkedin.com/in/saloni-saraiya) and we can discuss such cool Technical Stuff and Tools to make our development life easier 😉

Have fun Coding. Bye. 👋

**References**

 1. [MongoDB](https://www.mongodb.com/)

 2. [NodeJS](https://nodejs.org/)


- By Saloni Saraiya
(Programmer Analyst | Dhiwise)