| > 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 }; |
+21
| 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. |
+29
| 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" | ||
| } | ||
| } | ||
| } |
+3
-4
| # 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); | ||
| ``` |
-8
| 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); |
-25
| // 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, ''); | ||
| } | ||
| } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
4688
77.11%0
-100%10
66.67%68
195.65%0
-100%0
-100%0
-100%Yes
NaN11
-8.33%