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

plus.application

v1.1.14

Published

Application base: config + IoC container

Downloads

35

Readme

Application base: config + IoC container

The main goal of this package that loading app configuration and app services.

it uses 2 packages plus.container and plus.config and helps to manage application configuration and dependency injection. it has 2 parameters dir and env it loads configuration and container (services) from file system for some environment.

Usage

Configuration based on config npm package.

Dir

|-- default.js
|-- dev.js
|-- production.js
|-- container.js
|-- container_dev.js
|-- container_production.js
`-- container_test.js

Please take a look config for more details about configuration ways. It supports configuration in *.js, *.json, *.yml.

Confguration example
//default.js
module.exports = {
    port: 3000
}

App.js

// app.js example
    var Application = require('plus.application');

    var app = new Application({
        dir: __dirname,
        env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
    });
    
    app.config.get('port'); // 3000
    app.container.get('myService1'); // it should be service, will explain soon.

    // app.config instanceof require('plus.config')
    // app.container instanceof require('plus.container')

container.js

// container.js example
module.exports = function (container) {
    var Class1 = function(){  }
    var Class2 = function(){ }

    container.register('myService1', Class1);
    container.register('myService2', Class2);
    
    // more effective way of course
    container.register('myService3', require('../services/MyService3'), ['myService1', 'myService2']);
    
}

more details about container configuration here plus.container its ES5/ES6 dependency injection container.

Wrap

wrapper example for app it adds config and container

        var express = require('express');
        var app = express();

        new Application({
            dir: __dirname,
            env: process.env.NODE_ENV || 'dev'
        }).wrap(app);

        app.config.get('port'); // 3000
        app.container.get('myService1') // new Class1
        //BUT: app.container.get('myService1') === app.container.get('myService1')
        
        // nested access
        app.container.get('config/port') // 3000
        
        // for example
        app.listen(app.container.get('config/port'))
        // same thing is: app.listen(app.config.get('port'))

Please take a look on:

  • plus.container - https://www.npmjs.org/package/plus.container
  • plus.config - https://www.npmjs.org/package/plus.config

Alternative configuration way with json(s) only.

This configuration based on nconf and this is alternative way.

Dir
|-- config.json // main config
|-- config_dev.json // env config
|-- config_prod.json
|-- config_test.json
|-- container.js // main container
|-- container_dev.js // env container
|-- container_production.js
`-- container_test.js
config.json

config.json example

{
    "port": 3000
}

Take a look nconf for more info. if you need this way.

Create shortcut

    var app = require('plus.application').create({
         dir: __dirname,
         env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
     });

its equal to

    var app = new Application({
        dir: __dirname,
        env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
    });

Have a fun and manage your applications! +1G Team

Be happy!