IFNode #

Description #

IFNode is a factory method for creating instances of Application class.

Incoming argument presented like options for Application constructor, alias of created application instance or empty (first created by IFNode invoke) argument.

Definition #

JSDoc syntax #

 * @interface IFNode
 * @function
 * @param   {string|ApplicationOptions} [options]
 * @returns {Application}

TypeScript syntax #

interface IFNode {
    (options?: string|ApplicationOptions): Application

Arguments #

Name Type Description
options ApplicationOptions Creates and returns Application instance by options
string Returns Application instance with alias option from ApplicationOptions or undefined
undefined Returns first created Application instance by IFNode invoke or creates and returns new instance

Returns #

Type Description
Application Application instance

Example #

Create application with default config #

app.js #

const Assert = require('assert');
const IFNode = require('ifnode');

const app1 = IFNode({
    project_folder: __dirname,
    alias: 'application'
const app2 = IFNode('application');
const app3 = IFNode();

Assert.equal(app1, app2);
Assert.equal(app2, app3);

Create application with custom config #

config/dev.js #

module.exports = {
    site: {
        local: {
            port: 3000

app.js #

const Assert = require('assert');
const IFNode = require('ifnode');
const app = IFNode({
    project_folder: __dirname,
    alias: 'application',
    environment: 'dev'

Assert.equal(app.config.environment, 'dev');
Assert.equal(app.config.site.local.origin, 'http://localhost:3000');
Table of Content