Skip to main content

Getting started

You can start with Inversify HTTP in two ways:

  1. Scaffold a sample app with @inversifyjs/create-http if you want a working project to experiment with.
  2. Install the packages yourself if you prefer to add Inversify HTTP to an existing project or follow each step.

Scaffold a sample app

@inversifyjs/create-http generates a TypeScript HTTP app with an adapter of your choice, a Prisma-backed todo API, OpenAPI docs, and request validation.

npm create @inversifyjs/http@latest my-app

The CLI prompts for a package manager (npm, pnpm, or yarn) and an HTTP adapter (express, fastify, hono, or uwebsockets). You can also pass them as flags:

npm create @inversifyjs/http@latest my-app -- --pm npm --adapter express

The CLI creates the project, installs dependencies, and builds it. The sample uses PostgreSQL; start the database from the generated docker-compose.yml, apply migrations, and run the app:

cd my-app
docker compose up -d
npm run db:migrate
npm run serve

Then open http://localhost:3000/docs for the generated OpenAPI UI, or http://localhost:3000/status to check that the server is up. The sample includes a todo API under /todos.

When you are ready to understand each piece, start with Controllers, or follow the manual setup below.

Install the packages yourself

Install dependencies

To get started with Inversify HTTP, first install the required packages.

Begin by installing the inversify packages and reflect-metadata:

npm install inversify reflect-metadata @inversifyjs/http-core
warning

Make sure to enable the Experimental Decorators and Emit Decorator Metadata options in your tsconfig.json.

Choose an HTTP adapter

Inversify HTTP works with several HTTP frameworks. Choose the adapter that best fits your needs:

npm install @inversifyjs/http-express-v4

Configure server

After installing the packages, create a server to listen for incoming requests. Below is a basic example of setting up an Express server with Inversify HTTP.

const container: Container = new Container();

const adapter: InversifyExpressHttpAdapter = new InversifyExpressHttpAdapter(
container,
);

const application: express.Application = await adapter.build();

application.listen(3000);

The server is ready to receive requests, but there are no handlers yet. Add a Controller to handle incoming requests.