Upgrade Guide: v3 to v4
Migrate an ExpressoTS 3.x application to the 4.x line (4.0.0 and later).
Prerequisites
| Requirement | Version |
|---|---|
| Node.js | 20.19.0+ |
| Current app | ExpressoTS 3.x |
Breaking changes summary
Two things break when moving a v3 app to v4: a handful of public names were removed, and .env loading became explicit. Everything else is additive or opt-in.
Removed APIs and their replacements
| Removed in v4 | Use instead |
|---|---|
AppFactory / AppFactory.create(App) | await bootstrap(App) from @expressots/core |
InMemoryDataProvider, InMemoryDataTable | InMemoryDBProvider |
LazyServiceIdentifer (typo alias) | LazyServiceIdentifier |
AppContainer#viewContainerBindings() | AppContainer#introspect() or getFormattedBindingsView() |
Logger#formatMessage() (legacy) | The logger formats through transports; nothing to call |
AppFactory is the one most code, and most AI coding assistants, still reach for. Since 4.3.0 the name exists again only as a compile-time tombstone: AppFactory.create(...) fails to compile with an error that names the replacement, and throws the same message at runtime. Projects scaffolded by the CLI ship an AGENTS.md with these rules, and expressots llms prints them for the installed version.
v3:
import { AppFactory } from "@expressots/core";
import { App } from "./app";
AppFactory.create(App).then((app) => app.listen(3000));
v4:
import { bootstrap } from "@expressots/core";
import { App } from "./app";
void bootstrap(App); // App extends AppExpress; port from PORT or 3000
.env files are now opt-in (ADR-001)
In v3.x the framework called dotenv.config() automatically. In v4 you opt in by passing envFileConfig to bootstrap(). This was changed because containerised deployments (Docker, Kubernetes, serverless) inject env vars via process.env and a missing .env file used to trip alarms in production.
v3.x (implicit):
import { AppFactory } from "@expressots/core";
import { App } from "./app";
AppFactory.create(App).then((app) => app.listen(3000));
// .env was always loaded
v4 (explicit):
import { bootstrap } from "@expressots/core";
import { App } from "./app";
await bootstrap(App, {
envFileConfig: {
files: { development: ".env", production: ".env.prod" },
autoCreateTemplate: true,
},
});
If you do nothing, v4 will silently skip .env loading and rely on process.env only. CI environments are auto-detected (GitHub Actions, GitLab CI, Jenkins, generic CI=true).
Recommended alternative: call
loadEnvSync()(also from@expressots/core) directly insrc/main.tsbeforebootstrap(App). This is what theapplicationandapplication-with-eventstemplates do. It's an explicit, side-effect-free import that loads.env,.env.${NODE_ENV}, and the matching.localoverrides, with no extrabootstrap()config to remember:src/main.tsimport { bootstrap, loadEnvSync } from "@expressots/core";import { App } from "./app";loadEnvSync();void bootstrap(App);Use
envFileConfigonly when you need bootstrap-time validation (required,validateValues) orautoCreateTemplate.
For the full rationale see ADR-001 in expressots/packages/core/src/application/.docs/decision-log.md.
New in v4.0.0 (non-breaking)
Nothing in this section requires code changes. These are additive features you can adopt incrementally after the upgrade.
Studio is part of v4.0.0
@expressots/studio and @expressots/studio-agent ship alongside @expressots/core in the v4.0.0 release. Install both as dev dependencies:
npm install -D @expressots/studio @expressots/studio-agent
The agent auto-activates when NODE_ENV=development and the package is installed; no app.ts changes are needed. Production deployments pay zero runtime cost. See the Studio section for the full tour, including supply-chain and runtime posture security analysis.
Interceptors, events, lazy loading, content negotiation, advanced authorization
These are all new in v4.0.0. None of them require changes to a v3 app; you opt in when you want them. See the dedicated pages under Features and Guides.
Step 1: Update Dependencies
Update your package.json dependencies to the latest versions:
{
"dependencies": {
"@expressots/core": "^4.3.0",
"@expressots/adapter-express": "^4.3.0",
"@expressots/shared": "^4.3.0"
},
"devDependencies": {
"@expressots/cli": "^4.3.0"
}
}
Then run:
- npm
- yarn
- pnpm
npm install
yarn install
pnpm install
Step 2: Update Node.js Version
Ensure your Node.js version is 20.19.0 or higher:
node --version
Step 3: Application Changes
Bootstrap (required)
Replace AppFactory.create() with bootstrap(). It builds the container, runs the AppExpress lifecycle hooks, starts the server, and wires graceful shutdown; there is no separate listen() call.
Before (v3):
import { AppFactory } from "@expressots/core";
import { App } from "./app";
AppFactory.create(App).then((app) => app.listen(3000));
After (v4):
import { bootstrap } from "@expressots/core";
import { App } from "./app";
await bootstrap(App);
// Or with options
await bootstrap(App, {
port: 4000,
appName: "My API",
appVersion: "1.0.0",
});
Application class (no changes)
The AppExpress lifecycle keeps its v3 shape: configContainer(), globalConfiguration(), configureServices(), postServerInitialization(), serverShutdown(). Controllers, providers, modules and decorators are unchanged.
Step 4: New Features (Optional)
Interceptors
Add interceptors to your routes:
import { UseInterceptors, PerformanceInterceptor, LoggingInterceptor } from "@expressots/core";
@controller("/users")
export class UserController {
@Get("/")
@UseInterceptors(PerformanceInterceptor, LoggingInterceptor)
getUsers() {
return this.userService.findAll();
}
}
Event System
Create type-safe events:
// events/user.events.ts
export class UserCreatedEvent {
constructor(
public readonly userId: string,
public readonly email: string
) {}
}
// handlers/user-created.handler.ts
import { provide, OnEvent, IEventHandler } from "@expressots/core";
import { UserCreatedEvent } from "../events/user.events";
@provide(UserCreatedHandler)
@OnEvent(UserCreatedEvent)
export class UserCreatedHandler implements IEventHandler<UserCreatedEvent> {
handle(event: UserCreatedEvent) {
console.log(`User created: ${event.userId}`);
}
}
Testing Module
Use the new testing utilities:
import { createTestApp, request } from "@expressots/core";
describe("UserController", () => {
let app: any;
beforeAll(async () => {
const testApp = await createTestApp(App);
app = testApp.app;
});
test("GET /users", async () => {
await request(app)
.get("/users")
.expectStatus(200);
});
});
Enhanced Configuration
Use type-safe configuration:
import { defineConfig, Env } from "@expressots/core";
export default defineConfig({
database: {
url: Env.string("DATABASE_URL", { required: true }),
pool: Env.number("DB_POOL_SIZE", { default: 10 }),
},
});
Step 5: Testing
After upgrading, run your tests to ensure everything works:
- npm
- yarn
- pnpm
npm test
yarn test
pnpm test
Upgrading from 4.4 to 4.5
4.5 removes and renames nothing, and micro(), cloudflareAdapter, awsLambdaAdapter and vercelAdapter work as before. One change alters what a deployed application sends, on two runtimes.
On Workers and Lambda, an unset NODE_ENV means production
Cloudflare Workers and AWS Lambda do not set NODE_ENV, and an unset NODE_ENV counted as development. A deployed application on either runtime therefore answered errors as in development:
4.4, NODE_ENV unset | 4.5, NODE_ENV unset | |
|---|---|---|
| Unexpected error, no error handler | Problem document with the error's message and stack trace | As in production: no message, no stack |
Unexpected error, setErrorHandler({ problemJson: true }) | detail is the error's message | detail is "An unexpected error occurred." |
| Route that does not exist | suggestions lists close routes | No suggestions |
The error still reaches your log. A NODE_ENV that is set is followed on every runtime, and on Node, Bun and Deno an unset NODE_ENV is still development. To keep the details in local runs, set NODE_ENV=development: in .dev.vars under wrangler dev (it is never deployed; expressots new writes it for new Worker projects), or in the local environment under sam local and similar tools.
Separately, awsLambdaAdapter's own answer to an error nothing else answered was { "error": "<the message>" }. It is now { "error": "Internal Server Error" }.
Moving a Worker to @expressots/micro
Optional: a Worker on micro() from @expressots/adapter-express keeps working. Moving it to @expressots/micro takes it from about 200 KiB to about 6 KiB gzipped and drops nodejs_compat. Handlers change shape, since there is no Express:
micro() from @expressots/adapter-express | @expressots/micro |
|---|---|
import { micro, cloudflareAdapter } from "@expressots/adapter-express" | import { micro } from "@expressots/micro" |
export default cloudflareAdapter(app.getApp()) | export default { fetch: app.handler } |
(req, res) => ... | (request, ctx) => ..., returning the response |
req.params, req.query | ctx.params, ctx.query (no bracket syntax) |
req.body | await ctx.body() |
res.status(201).json(user) | Response.json(user, { status: 201 }) |
req.cloudflare.env, req.services.get(token) | ctx.env, servicesOf(ctx.env).get(token), with tokens from @expressots/micro/cloudflare |
app.setErrorHandler({ problemJson: true }) | the default |
validateBody(schema) | validate in the handler or a middleware, for example with schema.parse(await ctx.body()) |
compatibility_flags = ["nodejs_compat"] and the iconv-lite alias | neither |
Express middleware does not run on @expressots/micro; write it as (request, ctx, next) => ....
New in 4.5
@expressots/micro: the fetch-native runtime, with@expressots/micro/cloudflareand@expressots/micro/node.expressots new --target cloudflarebuilds new Workers on it.
Upgrading from 4.3 to 4.4
4.4 removes and renames nothing, and an application that lists its controllers in modules runs on it without edits. One change can stop an application from starting, and it comes first. The rest change what an application does in the places listed.
An application serves the controllers its modules list
This is the one breaking change. Until 4.3 every class decorated with @controller was served as soon as its file was loaded, whether or not a module given to configContainer() listed it. In 4.4 an application serves the controllers its modules list, and only those.
If a controller is loaded and no module lists it, the application does not start. The error, EXP4002, names the controller. It is refused at start, and not just left out, so that its routes do not turn into 404s without a word.
- An application created from a template, or with
expressots generate, lists every controller already and is not affected. - Otherwise, add the controller to a module:
CreateModule([UserController]), given toconfigContainer(). - A test file that builds two applications loads the controllers of both. Pass
{ controllers: "listed" }as the second argument ofconfigContainer()so each serves its own. - To keep what 4.3 did, pass
{ controllers: "discovered" }.
Run expressots check before deploying: it reports this error without starting the server.
Two defaults change, neither in production
- An uncaught error with no error handler registered is answered with a JSON problem document, where it used to be Express's HTML page. Production answers as before. This applies to application classes and to
micro()applications alike. To get the same answer in every environment, callthis.Middleware.setErrorHandler({ problemJson: true }), orapp.setErrorHandler({ problemJson: true })in a micro application. See Error responses. - In development, the full start banner prints only at a terminal. When the output is piped or captured by a tool, and in test runs, the banner is compact. A style passed to
setBanner()still wins. An application started undercreateTestAppis also namedtestin what it prints at start. Only the printed text changes.
The type of an error response has a new value
Error responses name their kind of problem in type. Earlier releases sent https://expressots.dev/errors/<name>, a domain the project does not own. 4.4 sends https://doc.expresso-ts.com/docs/errors/<name>, and each one leads to a page.
| Before | 4.4 |
|---|---|
https://expressots.dev/errors/not-found | https://doc.expresso-ts.com/docs/errors/not-found |
.../errors/validation (the rfc7807 format) | https://doc.expresso-ts.com/docs/errors/validation-failed |
.../errors/<status> for an AppError with a status that has no page | about:blank |
A client that compares type against one of the old values needs the new one. A client that reads status is not affected.
Five fixes change what a request or a start gets
Each one is a case where the application did less than its source says.
- Validation with a class-validator class runs. With
addValidation()on, a body typed with a class-validator class was not checked. It is now, and a body that breaks its rules is answered with 400. @validatedBody(schema)applies zod and yup schemas, with or withoutaddValidation(). A zod or yup object schema passed to a validated decorator was not applied; an invalid body is now answered with 400.- A request whose rules cannot be applied is refused. When a class declares class-validator rules and
class-validatororclass-transformeris not installed, the request is answered with 500 and the log names the missing package (EXP3002). Such a request used to be accepted unchecked. Install both packages. - A start does not take over a port outside development. When the port is in use, development still stops the process that holds it. Anywhere else the start fails and names that process (
EXP4001), which keeps running. - A path parameter reaches its handler in the type its method declares.
@param("id") id: numberasks for a number. In a compiled build (tsc, so production and Jest runs), a route's path parameters were also converted with the parameter types of every route declared after it in the same controller. With a string, a number and a boolean route in one controller,GET /items/by-name/abchanded its handler0; only the route declared last was right. Each route now converts its own parameters and no others, matched by the name given to@param.
If a route starts answering 400 or 500 after the upgrade, it was accepting input its own schema forbids. If a handler had code to cope with a wrong path parameter (a number where it declares a string, NaN, 0 or false), that code can go.
New in 4.4
expressots check: find out whether the application would start, without opening a port.expressots inspect: routes, providers, middleware and dependencies in one call, as text or JSON.validateBody(schema): body validation for the routes of a micro application.EXPRESSOTS_LOG=json: one JSON object per log line, in any environment.- Framework codes: errors and development warnings end with a stable code and say what to change.
- A request to a controller costs less CPU: about 14% less on a route that returns a small JSON object. Nothing to change in an application.
Troubleshooting
Common Issues
-
Node.js Version Error
If you see errors about unsupported Node.js features, ensure you're using Node.js 20.19.0 or higher.
-
TypeScript Errors
Update your TypeScript to version 5.x or higher for best compatibility.
-
Dependency Conflicts
Clear your
node_modulesand lock file, then reinstall:rm -rf node_modules package-lock.jsonnpm install
Getting Help
If you encounter issues during the upgrade:
- Check the GitHub Issues
- Join our Discord community
- Read the documentation
Summary
| Step | Action |
|---|---|
| 1 | Update dependencies to the 4.x line |
| 2 | Ensure Node.js 20.19.0+ |
| 3 | Replace AppFactory.create() with bootstrap() and rename any other removed API from the table above |
| 4 | Decide how .env is loaded (loadEnvSync() or envFileConfig) |
| 5 | Run tests |
| 6 | Adopt new features (optional) |
Beyond the removed names and explicit .env loading, v4 is compatible with v3 application code. New features are additive and can be adopted gradually.