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

expressjs-env-conf

v1.0.2

Published

Nodejs project env config

Readme

简介

Expressjs 本身缺乏根据不同的环境来加载对应的配置文件的机制,这会导致很多配置都写在同一个文件下通过env来区分,我们的项目中会出现大量诸如

const env = process.env.NODE_ENV || 'development'
const config = {
  production: {
    sms: 'http://xx.xx.158.59:8000/jet/textmessage',
    vehicleInfo: 'http://cx.ins.xiaobeixx.com/quote/queryVehicleInfoForAppointment.json',
  },
  development: {
    sms: 'http://xx.xx.100.63:8010/jet/textmessage',
    vehicleInfo: 'http://xx.xx.96.131:8002/quote/queryVehicleInfoForAppointment.json',
  },
  preview: { 
  },
}
export default config[env]

配置多了,就不方便管理且影响代码的简洁,之前使用过PHP的CI框架,所以就想着能不能在Express体系下也进入该机制。

安装

npm install expressjs-env-conf -S

使用

在程序的入口处,一般是app.js上引入

import { EnvConf } from 'expressjs-env-conf'
new EnvConf(config.root).init()

其中config.root为配置文件的基础目录,执行完之后,就可以在全局使用$locaConf()方法

比如在某个Controller

const testConf = $loadConf('test.js')
console.log(testConf)

该test.js存储于developmenttest等环境变量对应的文件夹下。

API

所有能导出的对象

import { env, EnvConf } from 'Nodejs-env-conf'

new EnvConf(configBaseDir)

创建EnvConf实例

instance.init()

初始化环境配置,执行完之后,

  1. 会在config的基础目录下创建四个文件夹developmen, test, preview, production
  2. 会在全局对象下附加$loadConf方法,这样在任何地方都可以通过$loadConf加载配置。

env.get()

获取process.env.NODE_ENV

env.init()

初始化process.env.NODE_ENV

env.set()

设置process.env.NODE_ENV,但是有一些约束条件。

Build

npm run build

设置eslint忽略global

"globals": {
  "$loadConf": true
}

CHANGELOG

1.0.2

  1. 部分代码重构。

1.0.1

修复如果baseDir不存在的情况下,程序报的BUG

1.0.0

完成基本功能