Platforms

Node.js

Running mion APIs on Node.js using the http module.

Installation

npm install @mionjs/platform-node @mionjs/router

Quick Start

import {startNodeServer} from '@mionjs/platform-node';
import {initMionRouter} from '@mionjs/router';
import {routes} from './node-routes.ts';

await initMionRouter(routes);

const server = await startNodeServer({port: 3000});

console.log('Server running at http://localhost:3000');

Configuration

You can pass configuration options to initMionHttp:

import {startNodeServer} from '@mionjs/platform-node';
import {initMionRouter} from '@mionjs/router';
import {routes} from './node-routes.ts';

await initMionRouter(routes, {
    basePath: 'api', // API prefix
});

await startNodeServer({port: 3000});
For production deployments, consider using a process manager like PM2 or running behind a reverse proxy like nginx.

Type Reference

NodeHttpOptions

export interface NodeHttpOptions {
    protocol: 'http' | 'https';
    port: number;
    /** Native node's ServerOptions. By default maxHeaderSize defaults to 8KB, same as in latest node versions */
    options: ServerOptions;
    /** Set of default response header to add to every response*/
    defaultResponseHeaders: Record<string, string>;
    /**
     * 256KB by default, same as lambda payload
     * @link https://docs.aws.amazon.com/lambda/latest/operatorguide/payload.html
     * */
    maxBodySize: number; // default 256KB
}