Platforms

Node.js

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

Installation

npm install @mionkit/node @mionkit/router

Quick Start

import {createServer} from 'http';
import {initMionHttp} from '@mionkit/node';
import {routes} from './node-routes.ts';

const server = createServer(initMionHttp(routes));

server.listen(3000, () => {
    console.log('Server running at http://localhost:3000');
});

Configuration

You can pass configuration options to initMionHttp:

import {initMionHttp} from '@mionkit/node';
import {routes} from './node-routes.ts';

const handler = initMionHttp(routes, {
    prefix: '/api', // API prefix
    // ... other router options
});
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
}