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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dpjayasekara/tscore

v0.8.2

Published

TypeScript based Application bootstrapper for NodeJS based REST APIs

Downloads

5

Readme

TSCore

http://tscore.deepal.io/

The MIT License

TSCore is a dependency injection container to develop REST APIs with NodeJS. In comes with a built-in http server powered by Express.js. TSCore is completely written in TypeScript, and comes all the type definitions built in.

Why do you need it?

TSCore is not the silver bullet, but it helps you bootstrap your REST API in a matter of minutes. It comes with a built-in Express sever including,

  • JSON Body parser using body-parser
  • Basic auth header parser
  • Secure HTTP Headers configuration using helmet
  • A dependency injection container
  • Built-in bunyan logger

More customizations are coming!!!

Installation

npm i @dpjayasekara/tscore

Usage

For a sample application, please checkout : https://github.com/dpjayasekara/tscore-sample-app

Write your code as individual modules with the following signature

Module

The following is an example for a tscore module.

import { Constants } from '@dpjayasekara/tscore';

export default class YourModule {
    private container;
    private logger;
    private config;

    constructor({container, logger, config}) {
        // access the container instance
        this.container = container;

        // access the logger instance
        this.logger = logger;

        // access the configuration object for this module
        this.config = config;

        // triggers yourFunction() when all the modules are loaded
        this.container.on(Constants.EVENT.APPLICATION_START, this.yourFunction.bind(this));
    }

    public yourFunction() {
        // do your thing
    }
}

Launcher

You can use Launcher to to bootstrap your application.

import {Launcher, ConfigLoader} from '@dpjayasekara/tscore'

const launcher = new Launcher();

launcher
    .onBaseDir(__dirname)                           // optional function call. defaults to process.cwd()
    .withConfig(ConfigLoader.jsConfigLoader({    // optional if config loading is required
        filePath: './config.json'
    }))
    .withLoggerConfig({                             // optional if no explicit minimum log level or log file is not configured
        name: 'myapp',
        level: 'debug'
    })
    .module({ name: 'a', path: './moduleA.ts'})
    .module({ name: 'b', path: './moduleB.ts'})
    .module({ name: 'server', path: './main.ts'})
    .start();

What is happening here:

  • ModuleA is a typescript/javascript module which will be injected to the container with name a. This module can be accessed by any other injected module as follows assuming the module follows the aforementioned tscore module structure.
const moduleA = this.container.module('a');
  • ModuleB is a typescript/javascript module which will be injected to the container with name b
  • Server is the main module of our application. We need to start the server, only if all the other modules are loaded. This can be done by listening on the APPLICATION_START event emitted from the container. The following is the structure of your main module:
import { Container, Constants } from '@dpjayasekara/tscore';

export default class Main {
    private container;
    private logger;
    private config;
    private serviceA;
    private serviceB;

    constructor({container, logger, config}) {
        this.container = container;
        this.logger = logger;
        this.config = config;
        this.startServer = this.startServer.bind(this)
        this.requestLogger = this.requestLogger.bind(this)

        this.serviceA = this.container.module('a');
        this.serviceB = this.container.module('b');

        this.container.on(Constants.EVENT.APPLICATION_START, this.startServer);
    }

    private startServer() {
        // start the server
    }
}

In the above example, startServer() will be called once all the modules are loaded, and that is the exact place you need to fire up your server.

API

http://tscore.deepal.io

Roadmap

  • [x] Launcher:Async configuration loading support
  • [ ] Server:Customizing server headers
  • [ ] Server:Request signing module
  • [ ] Launcher:Custom logger support
  • [ ] Server:Configurable health check endpoint
  • [ ] Launcher:TSCore Submodules