Express public folder for Coremod Typescript Node.js application.


Keywords
coremod
License
ISC
Install
npm install @coremod/public@0.3.2

Documentation

Coremod logo

Coremod

Coremod is a lightweight application framework with essential Node.js application modules written in Typescript. Coremod is written and maintained by @alexgrozav.


Homepage · Issue Tracker


npm version Downloads



Table of contents

Installation

First, install the Coremod CLI globally.

npm install -g ts-node coremod

Next, add Coremod to your project and install all peer dependencies.

npm install -S coremod typeorm typeorm-seeding typedi typeorm-typedi-extensions bcrypt dotenv class-transformer class-validator routing-controllers routing-controllers-openapi event-dispatch express cors faker passport passport-jwt
coremod --help

Modules

Install the Official Coremod modules:

npm i -S @coremod/express
npm i -S @coremod/public
npm i -S @coremod/logger
npm i -S @coremod/typeorm
npm i -S @coremod/authentication

Configuration

Create a file called coremod.config.ts. The configuration uses the Babel configuration pattern.

import { CoremodConfiguration } from "coremod";

export const configuration: CoremodConfiguration = {
    modules: [
        require.resolve('@coremod/logger'),
        require.resolve('@coremod/express'),
        require.resolve('@coremod/public'),
        require.resolve('@coremod/typeorm'),
        [require.resolve('@coremod/authentication'), {
            configuration: {
                jwt: {
                    secretOrKey: '##helloworld1234##'
                }
            }
        }]
    ]
};

Writing a module

Create a local module in modules/local-module and add the following starter code to modules/local-module/index.ts:

import {
    CoremodModule,
    CoremodModuleOptions,
    CoremodModuleRuntimeConfiguration,
    CoremodModuleRuntimeContext,
    CoremodModuleRuntime,
    CoremodModuleOptions,
    CoremodModuleRuntimeConfiguration, 
    env
} from "coremod";

export const configuration: CoremodModuleRuntimeConfiguration = {
    host: env.get('HOST', 'localhost'),
    port: env.get('PORT', '3030')
};

export const runtime: CoremodModuleRuntime = (context: CoremodModuleRuntimeContext, configuration: CoremodModuleRuntimeConfiguration, moduleOptions: CoremodModuleOptions) => {
    console.log(context, configuration, moduleOptions)
};

export const moduleOptions: CoremodModuleOptions = {
    something: true
};

export default {
    namespace: 'local',
    moduleOptions,
    configuration,
    runtime,
} as CoremodModule;

Modules have the following format:

  • namespace is used to wrap the runtime configuration
  • moduleOptions is used to set the module initialization options, which shouldn't be available to other modules
  • configuration is merged to the configuration object passed to the runtime function
  • runtime function used to add and modify the functionality of the application. Gets access to configuration object and context (the object that stores instances such as the Express application or TypeORM connection)

Next, add it to your coremod.config.ts file:

import { resolve } from 'path';
import { CoremodConfiguration } from "coremod";

export const configuration: CoremodConfiguration = {
    modules: [
        [resolve(__dirname, 'modules', 'local-module'), {
            something: true,
            configuration: {
                host: '3031'
            }
        }]
    ]
}

Bugs and feature requests

Have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Versioning

For increased transparency and backward compatibility, Coremod is maintained under the Semantic Versioning guidelines.

Creators

Alex Grozav

Copyright and license

Code copyright 2017-2020 Coremod Authors. Code released under the MIT License.