Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-env-file

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-env-file - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

3

lib/index.js

@@ -62,5 +62,4 @@ 'use strict'

try {
// lines = fs.readFileSync(env_file, 'utf8').match(/((?:\s*\#\s*)?.*[\w+]+)\s*\=(\n|.*)/gmi) || []
lines = (fs.readFileSync(env_file, 'utf8') || '')
.split("\n")
.split(/\r?\n|\r/)
.filter(function (line) {

@@ -67,0 +66,0 @@ return /\s*=\s*/i.test(line)

{
"name": "node-env-file",
"description": "Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.",
"keywords": ["process", "env", "file", "files", ".env", "ENV", "process.env", "parse", "load", "export", "exports"],
"version": "0.1.6",
"keywords": [
"process",
"env",
"file",
"files",
".env",
"ENV",
"process.env",
"parse",
"load",
"export",
"exports"
],
"version": "0.1.7",
"homepage": "https://github.com/grimen/node-env-file",

@@ -38,3 +50,5 @@ "repository": {

"dependencies": {
"chai": "latest"
"chai": "latest",
"glob": "^4.3.5",
"temp": "^0.8.1"
},

@@ -41,0 +55,0 @@ "devDependencies": {

@@ -70,3 +70,3 @@ # NODE-ENV-FILE [![Build Status](https://secure.travis-ci.org/grimen/node-env-file.png)](http://travis-ci.org/grimen/node-env-file)

```javascript
env('./path/to/.env', {verbose: true, overwrite: true});
env('./path/to/.env', {verbose: true, overwrite: true, raise: false, logger: console});
```

@@ -105,32 +105,2 @@

## Notes
### Bash based approach:
**`Makefile`**
```bash
define LOAD_ENV
ENV_FILE=$${2:-'.env'}
echo "LOAD: $$ENV_FILE"
if [ -f $$ENV_FILE ]; then
while read line || [ -n "$$line" ]; do
if [[ "$$line" == *=* ]] && [[ "$$line" != #* ]]; then
# TODO: handle exports case
echo " export $$line"
eval "export $$line"
fi
done < "$$ENV_FILE"
fi
endef
export LOAD_ENV
env:
eval "$$LOAD_ENV"
...
```
## License

@@ -137,0 +107,0 @@

@@ -8,4 +8,48 @@ 'use strict'

var temp = require('temp')
var path = require('path')
var fs = require('fs')
var glob = require('glob')
var env = require('../')
var defaultTestPath = path.join(__dirname, 'fixtures')
var windowsCRTestPath = temp.mkdirSync('node-env-file.windows-cr')
function _fixture(filename, type) {
var _fixturesPath;
var types = ['windows-cr', 'default']
if (!type) {
type = types[Math.floor(Math.random() * types.length)]
}
switch (type) {
case 'windows-cr':
_fixturesPath = windowsCRTestPath
break
default:
_fixturesPath = defaultTestPath
}
return path.join(_fixturesPath, filename)
}
function _prepareFixtures() {
// Prepare: Windows CR/newline tests
glob.sync(path.join(defaultTestPath, '*'), {dot: true})
.forEach(function(fixtureFile) {
var tmpEnvFile = path.join(windowsCRTestPath, path.basename(fixtureFile))
var fixtureData = fs.readFileSync(fixtureFile, 'utf-8')
var fixtureDataWithCR = fixtureData.replace(/\n/gmi, "\r\n")
console.log(tmpEnvFile)
// console.log(tmpEnvFile, fixtureDataWithCR)
fs.writeFileSync(tmpEnvFile, fixtureDataWithCR, 'utf-8')
})
}
// temp.track()
// -----------------------

@@ -18,2 +62,4 @@ // Test

before: function() {
_prepareFixtures()
expect(env).to.be.a('function')

@@ -37,3 +83,3 @@ },

expect(function() {
env(__dirname + '/fixtures/.env.100', {raise: false})
env(_fixture('.env.100'), {raise: false})
}).to.not.throw(Error)

@@ -47,3 +93,3 @@ },

expect(function() {
env(__dirname + '/fixtures/.env.100')
env(_fixture('.env.100'))
}).to.throw(Error)

@@ -60,3 +106,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.100', {})
env(_fixture('.env.100'), {})
}).to.throw(Error)

@@ -73,3 +119,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.100', {overwrite: true})
env(_fixture('.env.100'), {overwrite: true})
}).to.throw(Error)

@@ -84,3 +130,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.100', {raise: false})
env(_fixture('.env.100'), {raise: false})
}).to.not.throw(Error)

@@ -93,3 +139,3 @@ }

expect(function() {
env(__dirname + '/fixtures/.env.0')
env(_fixture('.env.0'))
}).to.not.throw(Error)

@@ -106,3 +152,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.0', {})
env(_fixture('.env.0'), {})
}).to.not.throw(Error)

@@ -119,3 +165,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.0', {overwrite: true})
env(_fixture('.env.0'), {overwrite: true})
}).to.not.throw(Error)

@@ -132,3 +178,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.1')
env(_fixture('.env.1'))
}).to.not.throw(Error)

@@ -145,3 +191,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.1', {})
env(_fixture('.env.1'), {})
}).to.not.throw(Error)

@@ -158,3 +204,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.1', {overwrite: true})
env(_fixture('.env.1'), {overwrite: true})
}).to.not.throw(Error)

@@ -171,3 +217,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.2')
env(_fixture('.env.2'))
}).to.not.throw(Error)

@@ -184,3 +230,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.2', {})
env(_fixture('.env.2'), {})
}).to.not.throw(Error)

@@ -197,3 +243,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.2', {overwrite: true})
env(_fixture('.env.2'), {overwrite: true})
}).to.not.throw(Error)

@@ -210,3 +256,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.3')
env(_fixture('.env.3'))
}).to.not.throw(Error)

@@ -223,3 +269,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.4')
env(_fixture('.env.4'))
}).to.not.throw(Error)

@@ -237,3 +283,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.5')
env(_fixture('.env.5'))
}).to.not.throw(Error)

@@ -251,3 +297,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.0')
env(_fixture('.env.exports.0'))
}).to.not.throw(Error)

@@ -264,3 +310,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.0', {})
env(_fixture('.env.exports.0'), {})
}).to.not.throw(Error)

@@ -277,3 +323,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.0', {overwrite: true})
env(_fixture('.env.exports.0'), {overwrite: true})
}).to.not.throw(Error)

@@ -290,3 +336,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.1')
env(_fixture('.env.exports.1'))
}).to.not.throw(Error)

@@ -303,3 +349,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.1', {})
env(_fixture('.env.exports.1'), {})
}).to.not.throw(Error)

@@ -316,3 +362,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.1', {overwrite: true})
env(_fixture('.env.exports.1'), {overwrite: true})
}).to.not.throw(Error)

@@ -329,3 +375,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.2')
env(_fixture('.env.exports.2'))
}).to.not.throw(Error)

@@ -342,3 +388,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.2', {})
env(_fixture('.env.exports.2'), {})
}).to.not.throw(Error)

@@ -355,3 +401,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.2', {overwrite: true})
env(_fixture('.env.exports.2'), {overwrite: true})
}).to.not.throw(Error)

@@ -368,3 +414,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.3')
env(_fixture('.env.exports.3'))
}).to.not.throw(Error)

@@ -381,3 +427,3 @@

expect(function() {
env(__dirname + '/fixtures/.env.exports.4')
env(_fixture('.env.exports.4'))
}).to.not.throw(Error)

@@ -384,0 +430,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc