{ "_args": [ [ { "raw": "getenv@^0.7.0", "scope": null, "escapedName": "getenv", "name": "getenv", "rawSpec": "^0.7.0", "spec": ">=0.7.0 <0.8.0", "type": "range" }, "/home/jdaugherty/work/GT2/GT2-Android/node_modules/xdl" ] ], "_from": "getenv@>=0.7.0 <0.8.0", "_id": "getenv@0.7.0", "_inCache": true, "_location": "/getenv", "_nodeVersion": "6.5.0", "_npmOperationalInternal": { "host": "packages-16-east.internal.npmjs.com", "tmp": "tmp/getenv-0.7.0.tgz_1475771052413_0.6985008402261883" }, "_npmUser": { "name": "ctavan", "email": "dev@tavan.de" }, "_npmVersion": "3.10.3", "_phantomChildren": {}, "_requested": { "raw": "getenv@^0.7.0", "scope": null, "escapedName": "getenv", "name": "getenv", "rawSpec": "^0.7.0", "spec": ">=0.7.0 <0.8.0", "type": "range" }, "_requiredBy": [ "/xdl" ], "_resolved": "https://registry.npmjs.org/getenv/-/getenv-0.7.0.tgz", "_shasum": "39b91838707e2086fd1cf6ef8777d1c93e14649e", "_shrinkwrap": null, "_spec": "getenv@^0.7.0", "_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/xdl", "author": { "name": "Christoph Tavan", "email": "dev@tavan.de" }, "bugs": { "url": "https://github.com/ctavan/node-getenv/issues" }, "contributors": [ { "name": "Moritz von Hase" }, { "name": "Jonas Dohse", "email": "jonas@dohse.ch" }, { "name": "Jan Lehnardt" }, { "name": "Tim Ruffles", "email": "timruffles@gmail.com" }, { "name": "Ashwani Agarwal", "email": "ashwani.a@outlook.com" } ], "dependencies": {}, "description": "Get and typecast environment variables.", "devDependencies": {}, "directories": {}, "dist": { "shasum": "39b91838707e2086fd1cf6ef8777d1c93e14649e", "tarball": "https://registry.npmjs.org/getenv/-/getenv-0.7.0.tgz" }, "engines": { "node": "*" }, "gitHead": "82cb9fd68006090994daa14c2e6c2f9cd14b0ecc", "homepage": "https://github.com/ctavan/node-getenv", "keywords": [ "env", "environment", "config", "configuration", "12factor" ], "main": "./index", "maintainers": [ { "name": "ctavan", "email": "dev@tavan.de" } ], "name": "getenv", "optionalDependencies": {}, "readme": "# getenv\n\n[![Build Status](https://secure.travis-ci.org/ctavan/node-getenv.png)](http://travis-ci.org/ctavan/node-getenv)\n\nHelper to get and typecast environment variables. This is especially useful if you are building [Twelve-Factor-Apps](http://www.12factor.net/) where all configuration is stored in the environment.\n\n## Installation\n\n```\nnpm install getenv\n```\n\n## Usage\n\nSet environment variables:\n\n```bash\nexport HTTP_HOST=\"localhost\"\nexport HTTP_PORT=8080\nexport HTTP_START=true\nexport AB_TEST_RATIO=0.5\nexport KEYWORDS=\"sports,business\"\nexport PRIMES=\"2,3,5,7\"\n```\n\nGet and use them:\n\n```javascript\nvar getenv = require('getenv');\n\nvar host = getenv('HTTP_HOST'); // same as getenv.string('HTTP_HOST');\nvar port = getenv.int('HTTP_PORT');\nvar start = getenv.bool('HTTP_START');\n\nif (start === true) {\n // var server = http.createServer();\n // server.listen(port, host);\n}\n\nvar abTestRatio = getenv.float('AB_TEST_RATIO');\n\nif (Math.random() < abTestRatio) {\n // test A\n} else {\n // test B\n}\n\nvar keywords = getenv.array('KEYWORDS');\nkeywords.forEach(function(keyword) {\n // console.log(keyword);\n});\n\nvar primes = getenv.array('PRIMES', 'int');\nprimes.forEach(function(prime) {\n // console.log(prime, typeof prime);\n});\n```\n\n## Methods\n\nAll methods accept a fallback value that will be returned if the requested environment variable is not set. If the fallback value is omitted and if the requested environment variable does not exist, an exception is thrown.\n\n### env(name, [fallback])\n\nAlias for `env.string(name, [fallback])`.\n\n### env.string(name, [fallback])\n\nReturn as string.\n\n### env.int(name, [fallback])\n\nReturn as integer number.\n\n### env.float(name, [fallback])\n\nReturn as float number.\n\n### env.bool(name, [fallback])\n\nReturn as boolean. Only allows true/false as valid values.\n\n### env.boolish(name, [fallback])\n\nReturn as boolean. Allows true/false/1/0 as valid values.\n\n### env.array(name, [type], [fallback])\n\nSplit value of the environment variable at each comma and return the resulting array where each value has been typecast according to the `type` parameter. An array can be provided as `fallback`.\n\n### env.multi({spec})\n\nReturn a list of environment variables based on a `spec`:\n\n```javascript\nvar config = getenv.multi({\n foo: \"FOO\", // throws if FOO doesn't exist\n bar: [\"BAR\", \"defaultval\"], // set a default value\n baz: [\"BAZ\", \"defaultval\", \"string\"], // parse into type\n quux: [\"QUUX\", undefined, \"int\"] // parse & throw\n});\n\n```\n\n### env.url(name, [fallback])\n\nReturn a parsed URL as per Node's `require(\"url\").parse`. N.B `url` doesn't validate URLs, so be sure it includes a protocol or you'll get deeply weird results.\n\n```javascript\nvar serviceUrl = getenv.url('SERVICE_URL');\n\nserviceUrl.port; // parsed port number\n```\n\n### env.disableFallbacks()\n\nDisallows fallbacks in environments where you don't want to rely on brittle development defaults (e.g production, integration testing). For example, to disable fallbacks if we indicate production via `NODE_ENV`:\n\n```javascript\nif (process.env.NODE_ENV === 'production') {\n getenv.disableFallbacks();\n}\n```\n\n### env.disableErrors()\n\n`getenv` won't throw any error. If a fallback value is provided, that will be returned, else `undefined` is returned.\n\n```javascript\ngetenv.disableErrors();\nconsole.log(getenv(\"RANDOM\"));\n// undefined\n```\n\n### env.enableErrors()\n\nRevert the effect of `disableErrors()`.\n\n```javascript\ngetenv.disableErrors();\nconsole.log(getenv(\"RANDOM\"));\n// undefined\n\ngetenv.enableErrors();\nconsole.log(getenv(\"RANDOM\"));\n// Error: GetEnv.Nonexistent: RANDOM does not exist and no fallback value provided.\n```\n\n## Changelog\n\n### v0.6.0\n- Added getenv.boolish() support.\n\n### v0.5.0\n- Add getenv.url() support.\n\n### v0.4.0\n- Add getenv.disableFallbacks() support.\n\n### v0.3.0\n- Add getenv.multi() support.\n\n### v0.2.0\n- Rename git repository\n\n### v0.1.0\n- Initial release\n\n## Authors\n\n- Moritz von Hase (initial author)\n- Christoph Tavan \n- Jonas Dohse \n- Jan Lehnardt (@janl): `getenv.multi()` support.\n- Tim Ruffles : `disableFallbacks()`, `url()`\n- Ashwani Agarwal : `disableErrors()`, `enableErrors()`\n\n## License\n\nThis module is licensed under the MIT license.\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git://github.com/ctavan/node-getenv.git" }, "scripts": { "test": "make test" }, "version": "0.7.0" }