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

agile-express-app-factory

v1.0.5

Published

Agile Express.js application factory.

Downloads

13

Readme

About

agile-express-app-factory is an experimental dynamic Express.js application factory. This code based on idea of using some global configurations for assembling functional shreds into application.

Do notice! This package is part of agile applications development experiments. For this reason it is not recommended to use this one in real projects. But you can use it for your own experiments freely.

Represented module has lots of lacks. For example, you can't specify built-in Express.js middlewares. Theoretically it is possible to add more functionality to agile-express-app-factory to fit all Express.js features. But you can find out this task to be too tough.

So, considering all defects, is there reason to develop so intricate application factory? Maybe is it better to create application traditional way, without defining independent shreds? To answer these questions we have to conduct such experiments.

Installation

npm i --save agile-express-app-factory

Usage

This example can be found at /src/example-starter/ package directory. To start example code run npm run dev at your terminal in root directory.

Let's go through example code.

There is directories structure:

.
├── index.ts
├── config.ts
├── starter.ts
└── listeners
    ├── foo.ts
    └── router
        └── endpoint.ts
// config.ts

// Configurations factory.

import {CustomConfig} from '@custom-config';

import {Type} from '@entities/entity';
import {EntitiesSpec} from '@entities/specifiers/types';

export const getConfig = ():CustomConfig => ({
    port: 9009,
    specifiers: getSpecifiers()
});

/**
 * Creates specifiers of the routers.
 * Every router must have appropriate listener module.
 * Modules with listeners must be defined in a special directory.
 * Within this example listeners directory is 'listeners'.
 * 
 * Make notice it is allowed to define route path as string,
 * string pattern and regular expression.
 */
const getSpecifiers = ():EntitiesSpec => ([
    {
        name: 'foo',
        path: '/fo?o',
        type: EntityType.ENDPOINT
    },
    {
        name: 'router',
        path: '/router',
        type: EntityType.ROUTER,
        entities: [
            {
                name: 'endpoint',
                path: /^\/?(end)?point\/?$/i,
                type: EntityType.ENDPOINT
            }
        ]
    }
]);
// starter.ts

// Creates and starts Express.js application.

import {Application} from 'express';

import {Factory} from '@app-factory';
import {CustomConfig} from '@custom-config';

import {getConfig} from './config';

export const start = () => {
    doStart()
        .catch(console.error);
};

const doStart = async () => {
    const config = getConfig();

    const app = await createApp(config);

    app.listen(config.port);
};

const createApp = (config:CustomConfig):Promise<Application> =>
    AppFactory.create(config);
// index.ts

import * as starter from './starter';

starter.start();

Next step is to create listeners modules for the specified routes.

// listeners/foo.ts

// Route path for these listeners is defined as string pattern:
// 'fo?o'

import {Request, Response} from 'express';

export const get = (req:Request, res:Response) => {
    res.send('Hello from `listeners/foo.ts`. Method: GET.');
};

export const post = (req:Request, res:Response) => {
    res.send('Hello from `listeners/foo.ts`. Method: POST.');
};
// listeners/router/endpoint.ts

// Route path for these listeners is defined as regular expression:
// /^\/?(end)?point\/?$/i

import {Request, Response} from 'express';

export const get = (req:Request, res:Response) => {
    res.send('Hello from `listeners/router/endpoint.ts`. Method: GET.');
};

export const post = (req:Request, res:Response) => {
    res.send('Hello from `listeners/router/endpoint.ts`. Method: POST.');
};

GitHub repository

https://github.com/balovbohdan/agile-express-app-factory

Contributing

Pull requests and forks are welcome. You can use this code freely for your own experiments. If you have some questions or proposals feel free to write message.

License

MIT