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

ng-config-service

v0.1.8

Published

A simple configuration service for Angular 6.0 or later. It uses HttpClient to fetch configuration data during the Angular bootstrap.

Readme

ng-config-service

Build Status Version License Downloads

A simple and flexible runtime config service for Angular application.

Installing / Getting started

There are three steps to setup the config service using the default configuration file path of assets/config/config.json.

  1. Install the ng-config-service package: npm install ng-config-service
  2. Create a configuration JSON file assets/config/config.json in your project.
  3. Bootstrap the config service in the root module. Because the config service use the HttpClient to fetch the configuration data, please make sure that HttpClientModule is imported in the root module.

The last step uses a const bootConfigServiceProvider that is exported from the ng-config-service. This const is a APP_INITIALIZER provider that uses a factory method to load configuration data during Angular bootstrap. The following code is an example using the default configuration file path.

import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'
import { HttpClientModule } from '@angular/common/http'

import { bootConfigServiceProvider } from 'ng-config-service'

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, HttpClientModule],

  // use the APP_INITIALIZER to load configuration data
  providers: [bootConfigServiceProvider],
  bootstrap: [AppComponent],
})
export class AppModule {}

A Different Configuration Data URL

If you want to use a different URL of a configuration file path or an HTTP API, you only need to assign the URL to a pre-defined injection token NG_CONFIG_URL_TOKEN in the above providers metadata. The following is an example.

providers: [
  {
    provide: NG_CONFIG_URL_TOKEN,
    useValue: 'path/to/my-config-file.json',  // could be an URL API or an environment variable
  },
  bootConfigServiceProvider,
],

Usage

The config service can be injected and its public get<T>(key: string): T | undefined method is used to get a configuration value. Following is a demo:

import { ConfigService } from 'ng-config-service'

@Component({
  //...
})
export class MyComponent {
  constructor(private configService: ConfigService) {}

  myMethod() {
    const aValue = this.configService.get('aKey')
  }
}

Error

If the config service fails to load the configuration data, due to either an invalid URL or wrong JSON syntax, it throws an Error exception that stops the Angular application bootstrap.

Developing

The Design Document and the Development Document describe the design consideration and the development details.

Built With

The project uses Angular CLI.

Prerequisites

It should be compatible with Angular 6.0 or later.

Setting up Dev

The source code has two projects created by Angular CLI and uses its library support. It has a regular Angular application served as a demo project that uses the config service library. The config service source code is located in projects/ng-config-service folder.

Building

Because of the limitation of Angular CLI, both the package.json and the project/ng-config-service/package.json should use the name name of ng-config-service. For each new publish, update both package.json files to use the same version value.

In project root, build the library project using npm run build-lib.

The demo app is build with the regular Angular CLI: ng build. To run the demo, use ng serve --open and you should see the property value configured in assets/config/config.json file.

Deploying / Publishing

To create the NPM package, run npm run package. To publish the NPM package, run npm run publish.

The cross-var package is used to provide cross-platform portability.

Versioning

We use SemVer for versioning. For the versions available, see the link to tags on this repository.

Tests

We use the demo app to test configuration service. Use ng test to run the test.

Style guide

It uses tslint-angular and prettier to enforce a consistent code format. The detail styles are defined in the tslint.json file and the .prettierrc file.

Code Documentation

The project uses Compodoc to generate code documents. Just run npm run docs to generate documents in the dist/documentation folder.