Skip to content
+91-7795206615
|
info@habilelabs.io

  • Home
  • About
  • Services
    • Custom Application Development
    • UI/UX Designing
    • Web Application Development
    • Offshore Product Services
    • Technical Outsourcing
    • ERP Services
  • Company
    • Careers
    • Case Studies
  • Specialization
    • Frontend Frameworks
      • Angular
      • ReactJS
      • VueJS
      • HTML / CSS
      • Javascript /Jquery
      • Bootstrap
      • Material design
    • Backend Frameworks
      • NodeJS
      • Meteor
      • GraphQL
      • Loopback
      • Salesforce
      • Spring Boot
      • Odoo
      • Laravel
    • Database / ORM
      • MySQL
      • PostgreSQL
      • Oracle
      • MongoDB
      • Google Firebase
      • Mongoose
      • Sequelize
      • Hibernate / JPA
    • Languages
      • Java Script
      • Dot Net
      • Java
      • Python
      • C / C++
      • PHP
      • AI / ML
      • Type Script
    • Mobile Frameworks
      • Ionic
      • Native Script
      • Native Android App
      • Native iOS App
      • Google Flutter
      • React Native
  • Blog
  • Hire Us

Know 4 Types of Mistakes a Node JS Developer Makes

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security

Categories

  • Angular
  • Business Strategies
  • Cloud Services
  • CRM
  • Design Pattern
  • E-commerce
  • ERP Applications
  • Javascript
  • Meteor
  • Mobile development
  • Mongo DB
  • Node JS
  • Odoo
  • Our Partners
  • PHP
  • React
  • SAAS
  • Salesforce
  • SAP
  • Selenium
  • Tech stack Migration
  • Testing
  • UI-UX Design
  • Uncategorized
  • VAPT
  • Visualforce
  • Web Development
  • Web Security
types of mistakes a node js developer makes

Do you know what are the common mistakes a node js developer make? If not, let’s discuss 4 types of mistakes you should know about while working with node JS.
Before coming to the topic, let’s get a quick idea of what node.js is and why we use it.

Node JS is a cross-platform JavaScript run-time environment which allows you to execute JavaScript in server side. It’s completely open source framework so we can use this without any cost.

Why Node JS?

Node JS is based on asynchronous programming model and single threaded, non-blocking so all processes are concurrent and there is no parallelism. Code reusability is also achieved because of usage of same models and service interface between client-side and server-side.

Node JS provides super fast performance because of its unique features and MVC pattern but if we don’t follow quality standards performance and security issues can arrive.

So, I’ll be addressing 4 common Node JS problems or mistakes that I think are the most common mistakes done by Node JS developers.

1. Memory Leak

Memory leak is a very big issue as it causes serious performance issues in your application. So, while writing code you should keep in mind that the piece of code doesn’t cause any memory leaks.

Following are some of the ways to ignore this issue.

a. MongoConnect:

If you are using MongoConnect (Well known for session management and it stores each session in the database) in a Production environment it causes memory leak issue.

So the problem looks like:

1
2
3
4
5
6
7
8
var session = require('express-session'),
MongoStore = require('connect-mongo')(session);
app.use(session({
    store: new MongoStore({
      mongooseConnection: db.connection,
      collection: config.sessionCollection
    })
  }));

Assign it only for your development environment.
The solution for the problem:

1
2
3
4
5
6
7
8
if (process.env.NODE_ENV === 'development') {
app.use(session({
    store: new MongoStore({
      mongooseConnection: db.connection,
      collection: config.sessionCollection
    });
  }));
}

b. Global variable:

When we write code sometimes it happens that we forgot to write ‘var’ before variable so now this variable will be a global variable and it can cause a memory leak.

1
2
3
function welcomeMessage() {
message = ‘This message will be global variable’;
}

So, in above WelcomeMessage function, we forgot to write var before message variable so it can cause a memory leak.
To prevent such type of issues you should write the first line of each file with ‘use strict’;.

2. Duplicate code:

Code reusability is a major practice that should be followed. A good developer writes code once and reuses it all over the product. Just copying & pasting same code in every function or file is a very bad practice. I am going to share some tips by which you can ignore such things.

Let’s understand with Example:
When you write REST API. We know that we need domain(Model like User, Member) information in each function.
Like there are 2 functions:

1
2
3
4
5
6
exports.readUser = function(){
// Write code to find user info
}
exports.updateUser = function(){
// Write code to find user info before update user
}  

So, there is only 2 functions but it is possible that there is n number of function where you need Domain information. In your example, we need user information. So the best solution for this type of case?
Write a middleware for all API where you need Domain info.

1
2
3
4
5
6
7
8
9
'use strict';
 
module.exports = function(app) {
  // User Routes
  app.route('/api/user/read/:userId).get(users.read);
  app.route('/api/user/update/:userId).get(users.update);
  // Finish by binding the user middleware
  app.param('userId', users.userByID);
};

So, write your findOne code in middleware so you can use user info in every function where you need. You can assign that domain info into request parameter.

3. Unused code and variable:

Sometimes when we write code then and some requirement change occurs, we need to change our code logic but we forgot to remove that unwanted code.

Can you imagine how big the problem it can cause?

Let say if you are working on that project and you did this type of mistake. After some time, the new developer works on that project. Now, what happens? that developer will be so confused because you know that block of code we are not using.

So guys, write code this way so that every new developer can understand what you write. In any case, you want to keep that code you can just comment it out with a proper description so a new developer can understand easily.
Also, keep in mind that please remove an unused variable.

4. Ignoring already available libraries

Express middleware provides most common use library already. Like for file system ‘fs’, if you want to use for the file path, there is a library called ‘path’. But we ignore these common libraries and require another library for this type of purpose.
So, we are increasing our physical memory for that of the library which is already available.

Conclusion :

If you think that you are too doing these types of mistakes, it can cause poor product performance and security issues which will further decrease productivity.

So, try to ignore these types of common mistakes. Try to write clean and smart code so everyone can understand. If you want to become very good programmer keep in mind that you are writing code for others not for you. There is couple good blog written by our experts based on a good guideline for REST API and Angular.JS so you can read and try to implement these measures into your code.

Habilelabs provides web based and mobile based application development services with high quality.

Hope you find this post “Node JS Mistakes” helpful, so don’t Forget to share with friends on Facebook.

If you have any query then ask me in the comment box.

Posted byashuJuly 24, 2017February 25, 2022Posted inNode JS, Web DevelopmentTags: Node Js coding, Node Js Mistakes, Node Js Mistakes by developers, node.js

Post navigation


:

Join the Conversation

1 Comment

  1. Jhanvi Mehta says:
    January 7, 2022 at 7:24 am

    You researched very well about node.js because I read your post and in this, you share about what type of mistakes are done by the node.js developers and I think that was right. so, Thank you for this post and keep sharing any tips about node.js.

    Reply
Leave a comment

Cancel reply

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

Leave a comment

Recent Posts

  • Mastering the essence of “Productivity”

    Mastering the essence of “Productivity”

  • Monorepo for React Native Apps with Nx

    Monorepo for React Native Apps with Nx

  • Quick Tips for Software Developers to stay ‘Healthy’

    Quick Tips for Software Developers to stay ‘Healthy’

  • Lean Software Development- How is it Beneficial for Start-ups?

    Lean Software Development- How is it Beneficial for Start-ups?

  • How IoT and Wearables are Improving Fintech in 2022?

    How IoT and Wearables are Improving Fintech in 2022?

  • The Ultimate Guide to Goal Setting Process

    The Ultimate Guide to Goal Setting Process

Talk to our experts now

Have a project or looking for development team? Contact us.

Get a quote

About Us

Habilelabs Private Limited is the ISO 9001:2015 certified IT company, which has marked its flagship in 20+ countries with 100+ projects successfully

Company

  • About
  • Blog
  • Careers
  • Hire Us
  • Privacy Policy

Contact Us

  • +91-9828247415
  • +91-9887992695
  • info@habilelabs.io

Follow Us

Office

  • Habilelabs Private Limited
    4th Floor, I.G.M. School Campus,
    Sec-93 Agarwal Farm, Mansarovar,
    Jaipur, Rajasthan India
    Pin:302020