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

@sevensweet/env-helper

v0.1.3

Published

混入模式使用环境变量

Readme

env-helper

一个基于环境变量的配置管理工具,用于处理不同环境下的配置需求。

项目结构

├── config/           # 项目配置目录
│   └── project.js    # 项目基础配置
├── lib/             # 核心库目录
│   └── configManage/ # 配置管理模块
│       ├── envManager.js    # 环境变量管理
│       └── projectManager.js # 项目配置管理
├── .env.development  # 开发环境配置
├── .env.preview     # 预览环境配置
├── .env.production  # 生产环境配置
├── .env.template    # 环境变量模板
├── Dockerfile       # Docker构建文件
└── docker-compose.yml # Docker编排文件

配置管理策略

环境变量管理

  • 开发环境:使用 .env.development 文件管理环境变量
  • 预览环境:使用 .env.preview 文件管理环境变量
  • 生产环境:使用 .env.production 文件管理环境变量
  • 环境变量模板:.env.template 提供所有可配置的环境变量示例

配置层级

  1. 基础配置(config/project.js)

    • 存放项目的基础配置
    • 不同环境共享的默认值
  2. 环境变量覆盖

    • 通过环境变量覆盖默认配置
    • 支持开发、预览、生产三种环境

使用方法

1. 环境变量配置

# .env.template 示例
TYPE_CODE=H5_PT
REDIS_HOST=127.0.0.1
WAC_BASE_URL=https://wac-kit.axinfu.com/wac_kit

2. 获取配置

const projectManager = require('./lib/configManage/projectManager');

// 获取当前环境完整配置
const config = projectManager.getConfig();

// 获取特定配置项
const wacBaseUrl = projectManager.getConfigByKey('WAC_BASE_URL');

3. 配置分类

  • BASE:项目共享基础配置
  • WAC:子应用配置
  • REDIS:Redis服务配置
  • LOG:日志服务配置(阿里云SLS)

Docker部署

1. 构建镜像

docker-compose build

2. 运行容器

docker-compose up -d

3. 环境变量注入

docker-compose.yml 中通过 environment 配置注入环境变量:

environment:
  - NODE_ENV=production
  - TYPE_CODE=H5_PT
  - PORT=3004

最佳实践

  1. 环境变量管理

    • 使用 .env.template 维护所有可配置项
    • 不同环境使用对应的 .env 文件
    • 敏感信息(密钥、密码)通过环境变量注入
  2. 配置分层

    • 基础配置:config/project.js
    • 环境配置:.env 文件
    • 运行时配置:Docker环境变量
  3. 开发流程

    • 本地开发使用 .env.development
    • 预览环境使用 .env.preview
    • 生产环境通过 Docker 环境变量注入
  4. 安全性

    • 敏感配置使用环境变量
    • 避免配置信息硬编码

注意事项

  1. 不要将包含敏感信息的 .env 文件提交到版本控制
  2. 确保 .env.template 包含所有必要的配置项
  3. Docker部署时正确配置环境变量
  4. 定期更新环境变量模板