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

@ksfcore/config

v2.0.5

Published

KSF 框架中用于获取服务配置文件

Downloads

2

Readme

Ksf-Config

Used to get config files in Ksf framework

Installation

npm install @ksfcore/config

Instantiation

Instantiate the object before using it:
var config = new KsfConfig (data)

data: The path to the config file or the configured @ksfcore/config-parser instance.

If the server runs by node-agent (or on Ksf platform,then you don't need to pass data

Enum

FORMAT

Defines the format of the config file:

  • C: C++ Config file formart
  • JSON: JSON format
  • TEXT: Normal text(Custom format)

LOCATION

Defines the position where the config files are stored:

  • APP: Config files are stored in the application
  • SERVER: Config files are stored in the servers

Methods

loadConfig([files ,]options)

Get config file content。

files(String|Array) It can be a single file name or an array, and if it is left empty, all the file contents will be obtained by default.

options(Object) Optional, accept the following parameters:

  • format: File format, default to e FORMAT.C
  • location: Stored position, default to be LOCATION.SERVER

Return array of following objects after call success:

  • filename: Filename
  • content: Content after file parsing

If only get one single file, it will return the parsed content of the file.

Example

Get the content of a.conf

config.loadConfig("a.conf").then(function(data) {
    console.log("content:", data);
}, function (err) {
    console.error("loadConfig err", err);
});

Get the content of a.conf and parse by json:

config.loadConfig("a.conf", {format : config.FORMAT.JSON}).then(function(data) {
    console.log("content:", data);
}, function (err) {
    console.error("loadConfig err", err);
});

Get content of a.conf which is stored in application:

config.loadConfig("a.conf", {location : config.LOCATION.APP}).then(function(data) {
    console.log("content:", data);
}, function (err) {
    console.error("loadConfig err", err);
});

Get content of a.conf and b.conf

config.loadConfig(["a.conf", "b.conf"]).then(function(data) {
    data.forEach(function(item) {
        console.log("filename:", item.filename);
        console.log("content:", item.content);
    });
}, function (err) {
    console.error("loadConfig err", err);
});

Get all config files of server:

config.loadConfig().then(function(data) {
    data.forEach(function(item) {
        console.log("filename:", item.filename);
        console.log("content:", item.content);
    });
}, function (err) {
    console.error("loadConfig err", err);
});

loadList(options)

Get list of config files(name of all config files)。

options(Object) Optional, accept the following parameters:

  • location: Stored position, default to be LOCATION.SERVER

Return array of file names after call success.

Example

Get all config file names of server:

config.loadList().then(function(filelist) {
    console.log("files:", filelist);
}, function(err) {
    console.log("loadList error", err);
});

loadServerConfig(options)

Get default config file(name is like App.Server.conf)。

options(Object) Optional, accept the following parameters:

  • format: File format, default to be FORMAT.C

Return parsed Content of config file after call success.

Example

Get default config file:

config.loadServerConfig().then(function(data) {
    console.log("content:", data);
}, function(err) {
    console.log("loadServerConfig error", err);
});

Events

configPushed

Emited when push config file to Ksf platform.

The callback function while provide pushed filename.

Example

Listen to push event, and get pushed file content :

config.on("configPushed", function(filename) {
    console.log("config pushed", filename);
    config.loadConfig(filename).then(function(data) {
        console.log("content:", data);
    }, function(err) {
        console.error("loadConfig err", err);
    });
});