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 -- --httpOr with a project name:
bash
npm create moost my-web-app -- --httpOther 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.mdWhat 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 devOpen http://localhost:3000/hello/World — you'll see Hello World.
How it works
new Moost()creates the application instancenew MoostHttp()creates the HTTP adapter — the bridge between Moost and Node's HTTP serverregisterControllers()tells Moost which classes contain route handlersinit()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
- Routing & Handlers — HTTP methods, route patterns, and handler basics
- Reading Request Data — extract query params, headers, cookies, and body
- Controllers — organize handlers into logical groups
- Vue + Moost (SSR) — fullstack Vue app with SSR, in-process API calls, and HMR