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

angular-environment-config

v1.0.0

Published

Environment configuration module for AngularJS

Readme

angular-environment-config Build Status

Hostname based environment configuration module for AngularJS

Contents

Get it

  • Download the source (minified);
  • Install using npm: run $ npm i angular-environment-config from your console; or
  • Install using bower: run $ bower install angular-environment-config from your console

Use it

  1. Add 'luminous.environment' to your main module's list of dependencies

    angular.module('myWebApp', ['luminous.environment']);
  2. Configure your environments during config phase using the $appEnvironmentProvider

    $appEnvironmentProvider
        .addEnvironment('local', ['127.0.0.1', 'localhost', /\.local$/i], {});
  3. Set default properties for all environments using $appEnvironmentProvider.setDefaults()

    $appEnvironmentProvider
        .setDefaults({ titlePrefix: '', apiUrl: '/api/' });
  4. Access the readonly config variables for the current environment using the $appEnvironment service via the config property.

    $document[0].title = $appEnvironment.config.titlePrefix + 'My App';

Stare intently at this example of it

angular.module('myWebApp', [
    'luminous.environment',
]);

angular.module('myWebApp')
    .config(myWebAppConfig)
    .controller('MainViewController', MainViewController);

myWebAppConfig.$inject = ['$appEnvironmentProvider'];
function myWebAppConfig (  $appEnvironmentProvider){
    
    $appEnvironmentProvider
    
        // Default config for all environments
        .setDefaults({
            titlePrefix: '',
            apiUrl: '/api/',
        })
        
        // Local environment
        // Matches: 127.0.0.1, localhost, or any hostname that ends with .local
        .addEnvironment('local', ['127.0.0.1', 'localhost', /\.local$/i], {
            titlePrefix: 'LOCAL :: ',
            apiUrl: 'http://localhost:7331/',
        })
        
        // Production environment
        // Matches: www.my-app.com, and my-app.com
        .addEnvironment('production', /^(|www\.)my-app.com$/, {
            apiUrl: 'https://api.my-app.com/',
        })
        
        // Set the default environment to Local
        // In case the hostname doesn't match one of the rules above
        .defaultEnvironmentName('local');
    
}

MainViewController.$inject = ['$appEnvironment', '$document'];
function MainViewController (  $appEnvironment,   $document) {
    
    // Set the document title
    
    $document[0].title = $appEnvironment.config.titlePrefix
        + 'My App - Powered by things, that do things!';
    

    // The the local environment will now have the document title:
    //     LOCAL :: My App - Powered by things, that do things!

    // Whereas the live environment will now have the document title:
    //     My App - Powered by things, that do things!

}

API


Provider


$appEnvironmentProvider


addEnvironment(environmentName, hostnames, config)

Adds a new environment config -- identified by environmentName -- that will be used when the Angular app's $location.host() matches one of the Strings or RegExps provided in hostnames.

$appEnvironmentProvider
    .addEnvironment('local', ['127.0.0.1', 'localhost', /\.local$/i], {
        // Local environment would match '127.0.0.1', 'localhost', and any
        // hostname that ends with .local
        titlePrefix: 'LOCAL :: ',
        apiUrl: 'http://localhost:7331/',
    })
    .addEnvironment('testing', 'test.my-app.com', {
        // Testing environment would match 'test.my-app.com'
        titlePrefix: 'TESTING :: ',
        apiUrl: 'https://test-api.my-app.com/',
    })
    .addEnvironment('production', /^(www\.|)my-app.com$/i, {
        // Production environment would match 'my-app.com' with or without
        // the leading 'www.', but would not match 'foo.my-app.com'
        apiUrl: 'https://api.my-app.com/',
    });
Arguments

Parameter | Type | Description ----------|------|------------ environmentName | String | The internal name for this environment (e.g. local) hostnames | String RegExp Array | Hostname String or RegExp or an Array of such, used to match against $location.host(). config | Object | The environment configuration, to be applied to a new AppEnvironmentConfig on top of any defaults specified via $appEnvironmentProvider.setDefault().

Returns

$appEnvironmentProvider


useConfigFor(environmentName).whenHostnameMatches(hostname)

Specify the environmentName to use when the hostname matches hostname.

$appEnvironmentProvider
    .useConfigFor('testing')
        .whenHostnameMatches(/^preview\.[a-z0-9-]{3,}\.my-app.com/i);
Arguments

Parameter | Type | Description ----------|------|------------ environmentName | String | The internal name of the environment (e.g. local) hostname | String RegExp | Hostname String or RegExp for matching against $location.host()

Returns

$appEnvironmentProvider


defaultEnvironmentName(environmentName)

Specify the environmentName to fall back on when none of the specified environment hostnames match the current hostname.

$appEnvironmentProvider
    .defaultEnvironmentName('local');

Important note: If a default environment name is not specified, and the current hostname does not match a configured host name, the $appEnvironment service will throw an EnvLookupError during init.

Arguments

Parameter | Type | Description ----------|------|------------ environmentName | String | The internal name of the environment to use when all else fails (e.g. local)

Returns

$appEnvironmentProvider


setDefaults(properties)

Set multiple default properties for $appEnvironment.config at once.

$appEnvironmentProvider
    .setDefaults({
        titlePrefix: '',
        apiUrl: '/api/',
    });
Arguments

Parameter | Type | Description ----------|------|------------ properties | Object | Default properties to add to $appEnvironment.config for all environments.

Returns

$appEnvironmentProvider


setDefault(key, value)

Specify a default value for key in $appEnvironment.config

$appEnvironmentProvider
    .setDefault('apiUrl', '/api/');
Arguments

Parameter | Type | Description ----------|------|------------ key | String | The property name value | * | The default value

Returns

$appEnvironmentProvider


Service


$appEnvironment


is(environmentName)

Determine if environmentName is the name of the current environment.

if (!$appEnvironment.is('production')) {
    // Logic that will effect all environments except 'production'
}
Arguments

Parameter | Type | Description ----------|------|------------ environmentName | String | The name of the environment

Returns

Boolean --- true if the current environment name is environmentName, otherwise false.


environmentName

String --- The name of the current environment

if ('testing' === $appEnvironment.environmentName) {
    // Logic that will only effect the 'testing' environment
} else {
    // Logic that will effect all environments except 'testing'
}

config

AppEnvironmentConfig --- Configuration object for the current environment, values are read-only.

$document[0].title = $appEnvironment.config.titlePrefix + 
    'MyApp - Created by things, for things';

hostname

String -- The hostname of the current environment.

if ('localhost' === $appEnvironment.hostname) {
    // Logic that will only occur if the hostname used to identify the current
    // environment was 'localhost'
}

isDefault

Boolean --- true if default environment configuration is being used, otherwise false.

if (true === $appEnvironment.isDefault) {
    // Logic that will only occur if the current environment is the environment specified in $appEnvironmentProvider.defaultEnvironmentName()
}