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 🙏

© 2026 – Pkg Stats / Ryan Hefner

autowired-js

v0.0.4

Published

IoC library for ES2015 classes inspired by Spring Framework IoC

Readme

autowired-js

Build Status NPM version

autowired-js IoC library for Node.js ES2015 classes inspired by Spring Framework IoC

Installation

$ npm install autowired-js

Simple Example

Create some beans

myBean1.js

/**
 * @Bean('myBean1')
 */
module.exports = class MyBean1 {

    print() {
        console.log('hello world');
    }

};

myBean2.js

/**
 * @Bean('myBean2')
 */
module.exports = class MyBean2 {

    /**
     * @Autowired
     */
    get myBean1() {};

    doWork: function() {
        this.myBean1.print();
    }

};

Initialize Context, scan for beans and use it.

app.js

var Autowired = require('autowired-js');

new Autowired('app', {
    /* optional config */
   'scan' : {
        'include': [/.+\.js$/], // array of regexps of files to parse
        'exclude' : ['node_modules']  // array of strings dirs to exclude
    }
}).scan(__dirname, (err, context) => {

    if (err) {
        return console.log(err);
    }

    app.getBean('myBean2').doWork();  // or use shortcut - app.get('myBean2')

    context.shutdown(() => {
        console.log('Context shutdown completed');
    });

});

Annotations

This section describe currently implemented annotations

@Bean('name')

This annotation marks your class as a "bean", it will be automatically scanner and put into context. Please note that you should keep only one bean per file and module.exports should export your class.

'name' parameter to @Bean is optional. If you do not provide it, bean name would be equal to you class name;

/**
 * @Bean
 */
module.exports = class MyBean {

    // implementation
};

@Initialize

If you mark any your method definition with this annotation, method would be invoked right after creating new instance of your bean and putting it in the context, but before any autowired injections. It would be done in async way, your method will be passed with a callback, and you need to invoke it after you complete initialization.

/**
 * @Bean
 */
module.exports = class MyBean {

    /**
     * @Initialize
     */
    doInit(callback) {

        // emulating long initialization...
        setTimeout(() => {
            callback();
        }, 1000);
    }
}

@Destroy

If you mark any your method definition with this annotation, method would be invoked on context shutdown, i.e. when calling context.shutdown(). Please note that beans in context would be destored in random order in parallel, so not make any assumptions on it.

/**
 * @Bean
 */
module.exports = class MyBean {

    /**
     * @Destroy
     */
    destroy(callback) {

        // emulating long destroying
        setTimeout(() => {
            callback();
        }, 1000);
    }

};

@Autowired

If you mark your property with this annotation, the dependency will be automatically injected in this property. Injected bean name should be the same as your property name, othwerise you can set injected bean name by providing parameter to annotation, for example: @Autowired('myRealBeanName').

/**
 * @Bean
 */
module.exports = class MyBean {

    /**
     * @Autowired('anotherBean')
     */
    get anotherBean() {}

    doWork() {
        this.anotherBean.doWork();
    }

};

@AfterPropertiesSet

If you mark any your method definition with this annotation, method would be invoked right after resolving all autowired dependencies.

/**
 * @Bean
 */
module.exports = class MyBean {

    /**
     * @Autowired
     */
    get anotherBean() {},

    /**
     * @AfterPropertiesSet
     */
    ready() {

        // can access another bean now
        this.anotherBean.doWork();
    }

};

Tests

$ sudo npm install nodeunit -g
$ npm test

Author

License

MIT