Node's Pocket Monsters

    TypeScript icon, indicating that this package has built-in type declarations

    0.8.2 • Public • Published


    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!!!


    npm i @dpjayasekara/tscore


    For a sample application, please checkout :

    Write your code as individual modules with the following signature


    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


    You can use Launcher to to bootstrap your application.

    import {Launcher, ConfigLoader} from '@dpjayasekara/tscore'
    const launcher = new 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'})

    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.



    • [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


    npm i @dpjayasekara/tscore

    DownloadsWeekly Downloads






    Unpacked Size

    64 kB

    Total Files


    Last publish


    • dpjayasekara