When you start learning JavaScript and Node.js for web development, you can’t help but wonder what backend frameworks are available. With a little bit of searching, the first framework you’ll see is Express.js. So your question is now “is Express.js a good idea for backend?”. If you are a junior developer working alone on a project, will your project be scalable and structured if you use Express? What exactly is Express.js? Is it a good backend framework for beginners and experienced JavaScript developers alike?
What is Express? – An Overview
Express.js or Express was created in node.js. Designed in JavaScript, it belongs to the MEAN MEVN and MERN stack. Express enables faster and better web development with template and routing functionality. A third-party library is also supported for integration to help simplify customization. Express is mostly used for creating APIs that connects to databases (SQL-based or MongoDB, etc.) and then consumed by web apps or other APIs. You can also create middleware functions using Express.
So, is Express.js a good idea for backend?
Considering that it is the most used and most downloaded backend framework, we can say that yes, Express.js is a good backend framework. With its minimalistic framework, you can start a web application project in minutes and it allows you to extend your API easily. You can use Express with both JavaScript and TypeScript. Using TypeScript with Express will allow you to code better via strict typing.
When to use Express.js?
Express is a good framework if you like your API code to be simple, minimal and flexible. It has no fixed code structure so you can arrange your code and files the way you want it. If your schedule is tight or you want a quick web app prototype, you can definitely use Express. And, if you use pure JavaScript you’ll create your backend code faster than if you use TypeScript.
Other benefits of Express.js include faster I/O for faster response times and single threads for synchronous and asynchronous processes. Newer versions enable data manipulation and routing to be simplified using MVC structures.
When not to use Express.js?
If you want an opinionated framework or additional structure to your backend development, you should consider other frameworks such as Nest.js, Next.js or Fastify. Projects created in Express can tend to be unmaintainable due to its flexibility. If you don’t know what you are doing, it is easy to accumulate technical debt. You can also use other frameworks like T3 (Next.js with TypeScript, Tailwind, tRPC with Prisma ORM), or tsoa (TypeScript with OpenAPI).
Express does not update frequently like other JavaScript libraries and packages, which can be good or bad. Good because there are fewer breaking changes for packages built on top of it. Bad because it looks like the project is unmaintained and no new features are added.
Suggestions
If you want a minimal and flexible framework that will be easier to maintain, use Express.js with TypeScript. You can use this for your first project even if you’re a solo developer. Using TypeScript will also allow better developer quality of life and will help with a growing codebase. But, TypeScript can also slow down a project due to figuring out third party types and weird behavior due to unfamiliarity with TypeScript itself. If that’s the case, just use JavaScript with Express.
Nest.js can be a really good framework, specially if you’re using Angular.js on the frontend. It is dubbed “Angular for backend”. It helps with larger projects due to its opinionated project structure. On the other hand, Nest.js can get punishingly complicated and there are times that using opinionated frameworks can slow you down, specially if the behavior that you want can’t be easily accomplished using the framework. Also, the documents for Nest.js are good but dependency injection can be tricky. Fastify is also a good option if you want a more modern and performant web framework.
Next steps
If this is your first web application project using Node.js, you can definitely use Express.js as said earlier. Being the most used framework means any common question you have you’ll have an answer to. It is a mature framework that is simple and easy to use and understand.
Being a JavaScript and Node.js developer, you see that you can go either the frontend and backend development path, or both. If your focus is on backend development, you can focus more on DevOps, CI/CD and cloud deployment, among others. You can study Express as a simple backend API and learn to deploy that API onto the cloud. And if you want to go the full stack web application route, using Express will allow you to quickly spin up web apps and maybe even use it for your next hackathon or side project. Either way, Express.js is a good choice for your backend development needs.