npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-node-server

v3.6.0-beta.9

Published

[![Build Status](https://travis-ci.com/henry781/ts-node-server.svg?branch=master)](https://travis-ci.com/henry781/ts-node-server)

Readme

ts-node-server [WIP]

Build Status

ts-node-server is node framework for developing RESTful web services in Typescript.

It pulls together some of the best node libraries :

  • Fastify : Fast and low overhead web framework, for Node.js

  • Pino : Super fast, all natural JSON logger for Node.js

  • Inversify : A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.

  • Swagger UI : A collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

  • MongoDB driver : Mongo DB Native NodeJS Driver

Features

Route decorators

ts-node-server use decorators to build fastify routes.

@controller('/v1/users')
export class UserController {

    @httpGet(':name')
    public async get(@pathParam('name')name: string) {
    }

    @httpPost()
    public async create(@queryParam('clone')clone: boolean) {
    }

Type validation

ts-node-server use tipify to validate, serialize and deserialize. It ensures that no property can be accidentally exposed.

@jsonObject()
export class StellarSystem {

    @jsonProperty('_id', ObjectIdConverter)
    private _id?: string;

    @jsonProperty('name')
    private _name?: string;

    @jsonProperty('planets', [Planet])
    private _planets?: Planet[];
} 

Swagger generator

ts-node-server use route decorators and tipify decorators to build a swagger configuration.

Metrics

ts-node-server imports fastify-metrics and exposes all your app metrics at /metrics.

Healthcheck

ts-node-server provides an healthcheck (/healthcheck). You can add more checks by extending Healthcheck class :

@injectable()
export class MongoHealthcheck implements Healthcheck {

    constructor() {
    }

    public getName(): string {
        return 'mongodb';
    }

    public check(): Promise<HealthcheckResult> {
        return {
            true,
            'content'
        };
    }
}

Authentication

Basic authentication

const server = new Server({
    container: container,
    auth: {
        basic: {
            'demo': {
                password: 'password',
                roles: ['admin']
            }
        }
    }
});

JWT authentication

const server = new Server({
    container: container,
    auth: {
        jwt: {
            authorizationUrl: 'http://localhost:9000/auth/realms/master/protocol/openid-connect/auth?nonce=',
            certificate: '.......CONTENT.......',
            application: 'test'
        }
    }
});

Protect a route

Protect a route using auth options:

@httpGet({ url: '/:name', auth: ['jwt', 'basic'] })
public async get(@pathParam('name')name: string) {
    ...
}

Allow only a list of roles to access to a route:

@httpGet({ url: '/:name', auth: { jwt: { role: ['admin'] } })
public async get(@pathParam('name')name: string) {
    ...
}

Get connected user

@httpGet({ url: '/:name', auth: 'jwt')
public async get(@pathParam('name')name: string, @auth()user: Principal {
    const logger = getLogger('get', this);
    logger.info('my name is', user.firstname, user.lastname, 'and my login is', user.login);
    ...
}

Generic client

ts-node-service provides GenericClient which is wrapper around request. GenericClient features:

  • Serialization / Deserialization with tipify
  • Error management and expected status
  • Authorization header format form a token or principal
  • Add request-id header to the request
export class UserClient extends GenericClient {

    public getUser(name: string) : Promise<User> {
        const options : RequestOptions<User> = {
            expectedStatus: 200,
            principal: principal,
            deserializeType: User
        };
        return this.get<User>('http://localhost/api/users/' + name, options);
    }
}

Logging

Get request logger

With fastify a logger is created for every request, it allows to add a request id to every log. To access to this logger:

const logger = getLogger();
logger.info('hello');

Usage

See ts-node-server-starter for an example.