Skip to content

Instantly share code, notes, and snippets.

@meyt
Created April 22, 2026 22:19
Show Gist options
  • Select an option

  • Save meyt/8135833fe511a27bd28d070ccef3bd0a to your computer and use it in GitHub Desktop.

Select an option

Save meyt/8135833fe511a27bd28d070ccef3bd0a to your computer and use it in GitHub Desktop.
Build express.js app with all dependencies (wasm and native binary excluded) into single file
import path from 'path'
import { fileURLToPath } from 'url';
import * as esbuild from "esbuild";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
try {
await esbuild.build({
entryPoints: [path.resolve(__dirname, './server.mjs')],
bundle: true,
sourcemap: false,
minify: false,
platform: "node",
target: ["node18.6"],
packages: "bundle",
define: {
"process.env.NODE_ENV": "'production'",
},
outfile: path.resolve(__dirname, '../dist/server.cjs')
});
console.log("Server bundled successfully for production! 🚀");
} catch (e) {
console.error("An error occurred during bundling:", e);
process.exit(1);
}
{
"name": "express-app",
"version": "1.0.0",
"type": "module",
"scripts": {
"build:server": "node esbuild.mjs",
},
"dependencies": {
"express": "^4.19.2"
},
"devDependencies": {
"esbuild": "^0.28.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment