• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Abhishek Tanwar

I build web & mobile experiences

  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS
You are here: Home / Building APIs / Structuring Express Application – How I do it?

Structuring Express Application – How I do it?

April 18, 2020 by Abhishek Tanwar

Starting an express application from scratch? You have come to the right place. In this post, I will share how I have been structuring my express applications. I have been using this for a while now.

Folder Structure

For any project folder structure is a crucial part. It helps to create a practice that will help you in your development life cycle, collaboration with your team and last but not the least – in transferring the code to someone else for maintenance. With the open source community catching up fast, all of these become very important.

So, lets look at the folder structure which I normally use for a standard express app based on Nodejs.

Express App folder structure
My standard folder structure – Express Application

Few lines about each of them.

FolderDescription
configThis folder is for all common configurations.
controllersThis is where I manage all my routes using any framework.
helpersThe place for all helpers utilities – encryption, date, string, formatting, transformation, logging etc.
middlewareThe place for storing all middleware functions. This is specifically for authentication & keylogging majorly for me.
modelThis is where I put all my model classes for interacting with the database. It can be any database framework. I personally prefer MongoDB
uiThis is the location of your UI code that needs to be served by the NodeJS server. It can be Angular, React etc. My personal choice and recommendation – Angular.
<BASE>This is the root directory of your project. Key files to mention are – index.js (server), db.js (database initialization) and .gitignore.

Default Packages

You have to be very sure about the packages to use. The basic guideline I follow is “Keep it to the minimum and use only if you want to utilise the full functionality of the package”.

Below are mandatory packages which I use with my NodeJS – Express application.

  • axios, my goto promise based HTTP rest-client library.
  • body-parser, parsing JSON data for modern APIs
  • compression, to reduce payload size and optimize for production.
  • express, the API framework
  • helmet, to remove all the unnecessary security headers which give more information about your application. Trust me – use this.
  • jsonwebtoken, my goto library for JWT
  • pm2, a process manager to run the application to support the load
  • cross-env, if you want to run commands on all platform – windows, Linux.
  • nodemon – hot reload for your express application.

Getting Production Ready

Always use a process manager. I prefer PM2 as mentioned in above dependencies. I am just getting too much used to PM2 (https://pm2.keymetrics.io). They have just grown to a more professional level to support the process manager function for node applications. From process manager, dashboard, logs, metrics – too much information this small utility provides. Give it a shot – you won’t regret it.

Hope you liked the post and found it useful in some ways. What tools or packages you use? What’s you goto folder structure. Please share your thoughts.

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X

Like this:

Like Loading...

Filed Under: Building APIs, Tips & Tricks Tagged With: best practices for express app, expressjs, folder structure, folder structure express, nodejs

Primary Sidebar

  • Behance
  • Email
  • Facebook
  • GitHub
  • LinkedIn

Popular Posts

How To Integrate React in JSP Application
SaaS, PaaS, IaaS
XQuery highlighting in Notepad++
Standard Design Patterns – Applied to JAVA
XQDT Installation on Eclipse JUNO

Categories

  • Building APIs
  • Building Mobile Apps
  • Building Web Apps
  • Coding Challenges
  • Extensions
  • Fullstack
  • Patterns
  • Tips & Tricks
  • Uncategorized
  • VSCode

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Recent Posts

  • 15+ VSCode Extensions To Improve Your Productivity
  • Productivity and Quality Extensions for ReactJS in VSCode..
  • My goto VSCode plugins for 2022…
  • How to enable MFA for your application in Node.JS?
  • Structuring Express Application – How I do it?

Categories

  • Building APIs (8)
  • Building Mobile Apps (1)
  • Building Web Apps (7)
  • Coding Challenges (3)
  • Extensions (1)
  • Fullstack (6)
  • Patterns (8)
  • Tips & Tricks (41)
  • Uncategorized (43)
  • VSCode (2)

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Archives

  • August 2023 (1)
  • March 2022 (1)
  • February 2022 (1)
  • November 2020 (1)
  • April 2020 (2)
  • May 2019 (1)
  • April 2019 (1)
  • March 2019 (1)
  • December 2018 (1)
  • July 2018 (4)
  • June 2018 (3)
  • March 2018 (1)
  • May 2016 (1)
  • December 2015 (1)
  • May 2015 (1)
  • April 2015 (2)
  • March 2015 (1)
  • December 2014 (2)
  • November 2014 (2)
  • October 2014 (1)
  • August 2014 (2)
  • July 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (4)
  • November 2013 (4)
  • October 2013 (3)
  • September 2013 (4)
  • August 2013 (2)
  • July 2013 (5)
  • June 2013 (9)
  • May 2013 (6)
  • April 2013 (2)
  • March 2013 (2)
  • January 2013 (1)
  • November 2012 (2)
  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS

Copyright © 2026

%d