New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nodeenv

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodeenv - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

45

Gruntfile.js
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
jshint: {
files: [ '**/*.js', '!node_modules/**/*.js', '!public/**/*.js' ],
options: {
jshintrc: 'jshint.json'
}
},
var tourism = require('tourism');
mochaTest: {
test: {
options: {
bail: true,
reporter: 'spec',
ui: 'tdd'
},
src: ['test/**/*.js']
}
},
watch: {
scripts: {
files: [ '**/*.js', '!node_modules/**/*.js' ],
tasks: [ 'default' ],
options: {
interrupt: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.registerTask('default', [ 'jshint', 'mochaTest' ]);
};
module.exports = tourism({
analyse: {
server: [ '**/*.js', '!node_modules/**/*.js' ]
},
test: {
server: [ 'test/**/*.js' ]
}
});

23

lib/nodeenv.js
'use strict';
var nodeenv = function (environment, callback) {
if (environment === undefined) { throw new Error('environment is missing.'); }
if (!callback) { throw new Error('callback is missing.'); }
var nodeenv = function (key, value, callback) {
if (!key) {
throw new Error('Key is missing.');
}
if (!callback) {
throw new Error('Callback is missing.');
}
var currentEnvironment = process.env.NODE_ENV;
var oldValue = process.env[key];
process.env.NODE_ENV = environment;
callback();
process.env.NODE_ENV = currentEnvironment;
process.env[key] = value;
callback(function () {
if (!oldValue) {
return delete process.env[key];
}
process.env[key] = oldValue;
});
};
module.exports = nodeenv;
{
"name": "nodeenv",
"version": "0.0.2",
"description": "nodeenv enables tests to control the NODE_ENV variable.",
"author": "Golo Roden <golo.roden@thenativeweb.io> (http://www.thenativeweb.io)",
"version": "0.1.0",
"description": "nodeenv enables tests to control Node.js environment variables.",
"contributors": [
{
"name": "Golo Roden",
"email": "golo.roden@thenativeweb.io"
}
],
"main": "lib/nodeenv.js",
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"grunt": "0.4.1",
"grunt-contrib-jshint": "0.7.1",
"grunt-contrib-watch": "0.5.3",
"grunt-mocha-test": "0.7.0",
"node-assertthat": "0.0.21"
"grunt": "0.4.5",
"node-assertthat": "0.2.0",
"tourism": "0.3.1"
},
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git://github.com/thenativeweb/nodeenv.git"
}
},
"license": "MIT"
}
# nodeenv
nodeenv enables tests to control the NODE_ENV variable.
nodeenv enables tests to control Node.js environment variables.
If you have any questions or feedback, feel free to contact me using [@goloroden](https://twitter.com/goloroden) on Twitter.
## Installation

@@ -19,20 +17,28 @@

Then, you can call the `nodeenv` function and specify the value for `NODE_ENV` you would like to use as well as a callback that contains the code that shall be run in the given environment.
Then, you can call the `nodeenv` function and specify the key of the environment variable you would like to set as well as its new value and a callback that contains the code that shall be run.
```javascript
nodeenv('dev', function () {
nodeenv('NODE_ENV', 'dev', function (done) {
// ...
done();
});
```
Once the callback returns, the previous value of `NODE_ENV` is automatically restored.
Once you call `done`, the previous value of the environment variable is restored.
## Running the tests
## Running the build
nodeenv has been developed using TDD. To run the tests, go to the folder where you have installed nodeenv to and run `npm test`. You need to have [mocha](https://github.com/visionmedia/mocha) installed.
This module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed nodeenv and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed.
$ npm test
$ grunt
Additionally, this module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, Grunt also analyses the code using [JSHint](http://www.jshint.com/). To run Grunt, go to the folder where you have installed nodeenv and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed.
## License
$ grunt
The MIT License (MIT)
Copyright (c) 2013-2014 the native web.
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.

@@ -12,11 +12,11 @@ 'use strict';

test('throws an exception if no NODE_ENV value is given.', function () {
test('throws an exception if no key is given.', function () {
assert.that(function () {
nodeenv(undefined, function () {});
nodeenv(undefined, '9e952479-953f-418b-9b5f-d24be4e2e443', function () {});
}, is.throwing());
});
test('does not throw an exception if an empty NODE_ENV value is given.', function () {
test('does not throw an exception if an empty value is given.', function () {
assert.that(function () {
nodeenv('', function () {});
nodeenv('8fa2f046-22af-475f-be5f-8e0546b164a5', undefined, function () {});
}, is.not.throwing());

@@ -27,26 +27,32 @@ });

assert.that(function () {
nodeenv('dev', undefined);
nodeenv('bda3f52f-46eb-43d0-9d5a-e657cdaa28e5', 'dfb86dcc-07c5-44ec-9d03-f4652512b538');
}, is.throwing());
});
test('runs the callback.', function () {
test('runs the callback.', function (done) {
var hasBeenRun = false;
nodeenv('dev', function () {
nodeenv('f580d7f8-4c1c-4169-9464-3e7f6295bb70', '70f73003-c717-4dd3-98c3-1d613e1805d4', function (restore) {
hasBeenRun = true;
restore();
assert.that(hasBeenRun, is.true());
done();
});
assert.that(hasBeenRun, is.true());
});
test('runs the callback using the given NODE_ENV value.', function () {
nodeenv('b8bf059f-d703-447c-82c8-977f78c8c0db', function () {
assert.that(process.env.NODE_ENV, is.equalTo('b8bf059f-d703-447c-82c8-977f78c8c0db'));
test('runs the callback using the given value.', function (done) {
nodeenv('d080c1f2-3c9e-445b-8921-701fd367d7ef', 'b8bf059f-d703-447c-82c8-977f78c8c0db', function (restore) {
assert.that(process.env['d080c1f2-3c9e-445b-8921-701fd367d7ef'], is.equalTo('b8bf059f-d703-447c-82c8-977f78c8c0db'));
restore();
done();
});
});
test('restores the original NODE_ENV value after running the callback.', function () {
var originalEnvironment = process.env.NODE_ENV;
nodeenv('dev', function () {
test('restores the original value after running the callback.', function (done) {
var originalEnvironment = process.env['dac75669-af5b-4b66-9777-b8dab5e29d13'];
nodeenv('dac75669-af5b-4b66-9777-b8dab5e29d13', '3362e020-a786-495d-8855-da5943354434', function (restore) {
restore();
assert.that(process.env['dac75669-af5b-4b66-9777-b8dab5e29d13'], is.equalTo(originalEnvironment));
done();
});
assert.that(process.env.NODE_ENV, is.equalTo(originalEnvironment));
});
});
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