Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

with-env

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

with-env - npm Package Compare versions

Comparing version
1.0.0
to
1.1.0
+4
.turbo/turbo-build.log
> with-env@1.1.0 build /home/runner/work/npm-packages/npm-packages/packages/with-env
> pkgroll
# with-env
## 1.1.0
### Minor Changes
- [`0bde08e`](https://github.com/MatthewSH/npm-packages/commit/0bde08e44a4c0aad03aab37d105e51a41f05848f) Thanks [@MatthewSH](https://github.com/MatthewSH)! - typescript and monorepo
'use strict';
var node_fs = require('node:fs');
function envApply(file) {
if (typeof file !== "string") {
envApply("./.env");
}
try {
const document = node_fs.readFileSync(file).toString().split("\n");
let i = -1;
while (++i < document.length) {
if (!document[i]) {
continue;
}
const row = document[i].split(/\s*=\s*/);
process.env[row.shift()] = row.join("=").replace(/['"]/g, "");
}
} catch (exception) {
throw new Error(
"The .env file could not be found or read correctly. Are you sure it is in the root directory?"
);
}
}
module.exports = envApply;
declare function envApply(file: any): void;
export { envApply as default };
declare function envApply(file: any): void;
export { envApply as default };
import { readFileSync } from 'node:fs';
function envApply(file) {
if (typeof file !== "string") {
envApply("./.env");
}
try {
const document = readFileSync(file).toString().split("\n");
let i = -1;
while (++i < document.length) {
if (!document[i]) {
continue;
}
const row = document[i].split(/\s*=\s*/);
process.env[row.shift()] = row.join("=").replace(/['"]/g, "");
}
} catch (exception) {
throw new Error(
"The .env file could not be found or read correctly. Are you sure it is in the root directory?"
);
}
}
export { envApply as default };
MIT License
Copyright (c) 2025 Matt Hatcher
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
import { readFileSync } from "node:fs";
function envApply(file) {
if (typeof file !== "string") {
envApply("./.env");
}
try {
const document = readFileSync(file).toString().split("\n");
let i = -1;
while (++i < document.length) {
if (!document[i]) {
continue;
}
const row = document[i].split(/\s*=\s*/);
// biome-ignore lint/style/noNonNullAssertion: Known to be non-null
process.env[row.shift()!] = row.join("=").replace(/['"]/g, "");
}
} catch (exception) {
throw new Error(
"The .env file could not be found or read correctly. Are you sure it is in the root directory?",
);
}
}
export default envApply;
+23
-14
{
"name": "with-env",
"version": "1.0.0",
"version": "1.1.0",
"description": "Read and then apply .env file in the working directory, assuming the .env exists",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"exports": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"author": {
"name": "matthewh",
"email": "hello@matthewh.in",
"url": "http://matthewh.in/"
"email": "matthatcher@pm.me",
"url": "https://matthewhatcher.com/"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": false,
"main": "index.js",
"homepage": "https://github.com/MatthewNPM/with-env",
"homepage": "https://github.com/MatthewSH/npm-packages",
"repository": {
"type": "git",
"url": "https://github.com/MatthewNPM/with-env"
"url": "https://github.com/MatthewSH/npm-packages"
},
"bugs": {
"url": "https://github.com/MatthewNPM/with-env/issues"
"url": "https://github.com/MatthewSH/npm-packages/issues"
},

@@ -33,5 +42,5 @@ "engines": {

"license": "MIT",
"dependencies": {
"fs": "0.0.2"
"scripts": {
"build": "pkgroll"
}
}
}
# With .env
Read and then apply .env file in the working directory, assuming the .env exists
## Install
`$ npm install with-env`
## Usage
## Usage
```javascript
require('with-env')();
require("with-env")();
console.log(process.env.MY_VARIABLE);
```
DB_HOST=localhost
DB_NAME=table
DB_USER=root
DB_PASSWORD=password
ADMIN_EMAIL=admin@email.com
ADMIN_NAME=Administrator
ADMIN_MOTTO="Oh yeah baby. Let's do this!"

Sorry, the diff of this file is not supported yet

// Coding standard for this project defined @ https://github.com/MatthewSH/standards/blob/master/JavaScript.md
require('../')();
console.log(process.env.ADMIN_MOTTO);
// Coding standard for this project defined @ https://github.com/MatthewSH/standards/blob/master/JavaScript.md
'use strict';
const $read = require('fs').readFileSync;
exports = module.exports = function envApply () {
var document;
try {
document = $read('./.env').toString().split('\n');
} catch (exception) {
throw new Error('The .env file could not be found or read correctly. Are you sure it is in the root directory?');
}
var i = -1;
var row;
while(++i < document.length) {
if (!document[i]) {
continue;
}
row = document[i].split(/\s*=\s*/);
process.env[row.shift()] = row.join('=').replace(/['"]/g, '');
}
}