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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lunjack-env

v3.0.6

Published

A simple package to read .env environment files

Readme

lunjack-env一个简单易用的 .env 环境变量文件读取工具

安装

npm i lunjack-env

特性

  • ✅ 自动检查并创建 .env 示例文件
  • ✅ 支持 env.变量名 的直接调用方式
  • ✅ 支持自定义 .env 文件路径
  • ✅ 自动将变量注入到 process.env
  • ✅ 多路径自动查找 .env 文件
  • ✅ 支持注释和空行
  • ✅ 友好的错误提示

.env 文件格式

在项目根目录或运行文件根目录创建 .env 文件:

# 数据库配置
DATABASE_URL=mysql://user:password@localhost:3306/dbname
API_KEY=your_api_key_here

# 应用配置
DEBUG=false
PORT=3000
NODE_ENV=development

API

属性访问

  • env.VARIABLE_NAME - 直接访问变量

方法

  • env.get(key, defaultValue) - 获取变量值
  • env.has(key) - 检查变量是否存在
  • env.getAll() - 获取所有变量
  • env.load() - 重新加载变量

文件查找顺序

  1. 自定义路径
  2. 当前工作目录的 .env 文件
  3. C盘用户主目录的 .env 文件

使用方法

默认配置(示例)

const {env} = require('lunjack-env');

// 直接使用变量
console.log(env.DATABASE_URL);
console.log(env.API_KEY);
console.log('数据库地址:', env.DATABASE_URL);
console.log('API密钥:', env.API_KEY);

// 或者使用方法
console.log(env.get('DATABASE_URL'));
if (env.has('SECRET_KEY')) {
  console.log('密钥存在');
}

// 获取所有变量
const allVars = env.getAll();
console.log('所有变量:', allVars);

自定义配置(示例):

const { config } = require('lunjack-env');
const env = config({
    path: './path/.env',  // 自定义路径 (自定义路径如果是相对路径,那么请以工作路径作为基准设置->向上或向下或同级)
    encoding: 'utf8',     // 字符集 (默认utf8)
    debug: true           // 调试模式 (默认false)
});

console.log(env.PORT); // 访问配置项
// 其它使用方式同默认配置(示例)...

错误处理

如果未找到 .env 文件,包会自动创建示例文件并退出进程。

这个包提供了完整的 .env 文件管理功能,包括自动创建示例文件、错误处理、多路径查找等特性,用户可以通过简单的 env.变量名 方式直接访问环境变量