Bundling Your Node.js Express App with esbuild

Adam Berg
3 min readNov 2, 2021

When setting up a backend node project, I have almost always defaulted to setting up a TypeScript to build the app using the outDir property in tsconfig.json.

// tsconfig.json
{
"compilerOptions": {
...
"outDir": "./built",
...
}
}

This worked well for local development as the node_modules folder sits right there and running the built file is a simple node built/index.js.

This did not work so well when it came time to deploy the backend code to a server. In order to successfully run on the server all of the files in the built folder needed to be synced as well as the entire node_modules folder.

If you’re reading this article you have probably seen the following meme before:

On some of my projects, the node_modules folder tallies up to over 700 MB. Even a fairly basic express app is 155.6 MB. Every deploy now requires uploading almost a full GB of data, for what surely amounts to much less actual code necessary.

Enter esbuild

esbuild is “An extremely fast JavaScript bundler”. You’re welcome to figure out how to bundle with webpack, but I have found esbuild to be unreasonably fast relative to webpack and a much simpler setup.

--

--

Adam Berg
Adam Berg

Written by Adam Berg

Building https://kaizen.place. writing about C, C++, rust, game development, web development, engineering management. https://devtails.xyz/

Responses (3)