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

@eric-gitta-moore/env2file

v1.2.0

Published

A tool for writing environment variables to files with support for base64 encoding and variable references

Readme

env2file

本项目使用 Trae AI 工具编写,注意鉴别~

一个简单的工具,用于将环境变量内容写入文件。

A simple tool to write environment variables to files.

功能特点 | Features

  • 支持将环境变量内容写入单个或多个文件
  • 支持自动创建目标文件所需的目录结构
  • 使用Base64编码确保特殊字符的正确传输
  • 支持通过分号分隔多个写入指令

安装 | Installation

# 全局安装
npm install -g env2file

# 或者使用 npx
npx env2file

# 或者使用 pnpx
pnpx env2file

使用方法 | Usage

环境变量格式 | Environment Variable Format

使用WRITE环境变量来指定写入指令,格式如下:

WRITE="[文件路径](Base64编码的内容)"

内容支持以下三种格式:

  1. Base64编码的直接内容:[文件路径](Base64内容)
  2. 环境变量引用:[文件路径]($ENV_VAR),对应 process.env.ENV_VAR
  3. Base64编码的环境变量内容:[文件路径](base64:$ENV_VAR),对应 Buffer.from(process.env.ENV_VAR).toString('base64')

多个写入指令可以用分号(;)分隔:

WRITE="[文件1](内容1的Base64);[文件2]($ENV_VAR2);[文件3](base64:$ENV_VAR3)"

示例 | Examples

  1. 写入单个文件:
# 将"Hello World"写入test.txt

# 使用全局安装的命令
WRITE="[./test.txt](SGVsbG8gV29ybGQ=)" env2file

# 或者使用 npx
WRITE="[./test.txt](SGVsbG8gV29ybGQ=)" npx env2file

# 或者使用 pnpx
WRITE="[./test.txt](SGVsbG8gV29ybGQ=)" pnpx env2file
  1. 写入多个文件:
# 同时写入两个配置文件
WRITE="[./config/db.json](eyJob3N0IjoibG9jYWxob3N0In0=);[./config/app.json](eyJwb3J0Ijo4MDgwfQ==)" env2file
  1. 在CI/CD流程中使用:
# GitHub Actions示例
steps:
  - name: Generate config files
    run: |
      WRITE="[./config.json]($(echo '{"key":"${{ secrets.API_KEY }}"}' | base64))" env2file

开发指南 | Development Guide

开发环境要求 | Requirements

  • Node.js >= 14.0.0
  • npm >= 6.0.0

本地开发 | Local Development

# 克隆项目
git clone https://github.com/yourusername/env2file.git

# 安装依赖
npm install

# 运行测试
npm test

测试 | Testing

项目使用 Jest 进行测试,测试文件位于 __tests__ 目录下。

# 运行测试
npm test

# 监听模式运行测试
npm run test:watch

# 生成测试覆盖率报告
npm run test:coverage

编写测试时,请确保:

  • 测试文件命名为 *.test.js
  • 覆盖主要功能和边界情况
  • 提供清晰的测试描述

调试 | Debugging

  1. 本地调试:
# 设置环境变量并运行
WRITE="[./test.txt](SGVsbG8=)" node --inspect-brk ./bin/env2file.js
  1. 使用 VS Code 调试:
    • .vscode/launch.json 中配置调试设置
    • 设置断点
    • 使用 VS Code 调试面板运行

注意事项 | Notes

文件路径处理 | File Path Handling

  • 支持相对路径和绝对路径
  • 如果目标文件所在目录不存在,会自动创建
  • Windows 系统下请使用正斜杠(/)或双反斜杠(\)作为路径分隔符

内容编码 | Content Encoding

  • 内容必须是 Base64 编码的字符串
  • 特殊字符(如换行符、引号等)需要先进行转义,再进行 Base64 编码
  • 建议使用 Buffer.from(content).toString('base64') 进行编码

多文件处理 | Multiple Files

  • 多个写入指令之间使用分号(;)分隔
  • 分号在文件内容中需要进行转义处理
  • 建议每个写入指令占用单独一行,提高可读性

安全性 | Security

  • 避免将敏感信息直接写入代码中
  • 在 CI/CD 环境中使用加密的环境变量
  • 注意文件权限设置

贡献指南 | Contributing

  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 创建 Pull Request

许可证 | License

MIT