Skip to content

Getting Started

Build an HTTP server with Moost in under a minute.

Prerequisites

  • Node.js 20.19+ (or 22.12+) — required by Vite, which powers the dev server
  • npm, pnpm, or yarn

Scaffold a project

bash
npm create moost -- --http

Or with a project name:

bash
npm create moost my-web-app -- --http

Other templates

npm create moost -- --ssr scaffolds a fullstack Vue + Moost app with SSR/SPA support. See Vue + Moost (SSR). Other options: --ws (WebSocket), --cli (CLI app). Run npm create moost without flags for interactive mode.

The scaffolder creates:

my-web-app/
├── src/
│   ├── controllers/
│   │   └── app.controller.ts
│   └── main.ts
├── package.json
├── tsconfig.json
├── vite.config.ts
└── README.md

What you get

main.ts — the entry point:

ts
import { MoostHttp } from '@moostjs/event-http'
import { Moost } from 'moost'
import { AppController } from './controllers/app.controller'

const app = new Moost()

const http = new MoostHttp()
app.adapter(http).listen(3000, () => {
    app.getLogger('[my-web-app]').info('Server started on port 3000')
})

app.registerControllers(AppController).init()

app.controller.ts — your first handler:

ts
import { Get } from '@moostjs/event-http'
import { Controller, Param } from 'moost'

@Controller()
export class AppController {
    @Get('hello/:name')
    hello(@Param('name') name: string): string {
        return `Hello ${name}`
    }
}

Run it

bash
npm install && npm run dev

Open http://localhost:3000/hello/World — you'll see Hello World.

How it works

  1. new Moost() creates the application instance
  2. new MoostHttp() creates the HTTP adapter — the bridge between Moost and Node's HTTP server
  3. registerControllers() tells Moost which classes contain route handlers
  4. init() wires everything together — resolves dependencies, binds routes, prepares interceptors

The @Get('hello/:name') decorator registers the method as a GET handler. The :name segment becomes a route parameter, extracted by @Param('name').

What's next

Released under the MIT License.