{"id":31904117,"url":"https://github.com/cloudfoundry-community/node-cfenv","last_synced_at":"2025-10-13T13:47:31.932Z","repository":{"id":17135700,"uuid":"19902138","full_name":"cloudfoundry-community/node-cfenv","owner":"cloudfoundry-community","description":"easy access to your Cloud Foundry application environment for node","archived":false,"fork":false,"pushed_at":"2021-08-04T23:37:42.000Z","size":75,"stargazers_count":74,"open_issues_count":8,"forks_count":20,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-09-19T16:23:53.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sra/node-cfenv","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudfoundry-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-18T03:40:10.000Z","updated_at":"2024-09-21T19:33:38.000Z","dependencies_parsed_at":"2022-07-26T01:49:43.716Z","dependency_job_id":null,"html_url":"https://github.com/cloudfoundry-community/node-cfenv","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/cloudfoundry-community/node-cfenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudfoundry-community%2Fnode-cfenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudfoundry-community%2Fnode-cfenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudfoundry-community%2Fnode-cfenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudfoundry-community%2Fnode-cfenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudfoundry-community","download_url":"https://codeload.github.com/cloudfoundry-community/node-cfenv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudfoundry-community%2Fnode-cfenv/sbom","scorecard":{"id":292651,"data":{"date":"2025-08-11","repo":{"name":"github.com/cloudfoundry-community/node-cfenv","commit":"fb0a2aab407bdfd01c6b275b0af952f08d3de000"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 4/29 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T18:40:41.349Z","repository_id":17135700,"created_at":"2025-08-17T18:40:41.349Z","updated_at":"2025-08-17T18:40:41.349Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015339,"owners_count":26085685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-13T13:47:26.968Z","updated_at":"2025-10-13T13:47:31.923Z","avatar_url":"https://github.com/cloudfoundry-community.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cfenv - easy access to your Cloud Foundry application environment\n================================================================================\n\nThe cfenv package provides functions to parse Cloud Foundry-provided environment\nvariables.  Provides easy access to your port, http\nbinding host name/ip address, URL of the application, etc.  Also provides\nuseful default values when you're running locally.\n\nThe package determines if you are running \"locally\" versus running as a\nCloud Foundry app, based on whether the `VCAP_APPLICATION` environment variable is set.\nIf not set, the functions run in \"local\" mode, otherwise they run in \"cloud\"\nmode.\n\n\nquick start\n================================================================================\n\n    var cfenv = require(\"cfenv\")\n\n    var appEnv = cfenv.getAppEnv()\n    ...\n    // start the server on the given port and binding host, and print\n    // url to server when it starts\n\n    server.listen(appEnv.port, appEnv.bind, function() {\n        console.log(\"server starting on \" + appEnv.url)\n    })\n\nThis code snippet above will get the port, binding host, and full URL to your HTTP\nserver and use them to bind the server and print the server URL when starting.\n\n\nrunning in Cloud Foundry vs locally\n================================================================================\n\nThis package makes use of a number of environment variables that are set when\nyour application is running in Cloud Foundry.  These include:\n\n* `VCAP_SERVICES`\n* `VCAP_APPLICATION`\n* `PORT`\n\nIf these aren't set, the `getAppEnv()` API will still return useful values,\nas appropriate.  This means you can use this package in your program and\nit will provide useful values when you're running in Cloud Foundry AND\nwhen you're running locally.  You can supply local versions of\n`VCAP_SERVICES` and/or `VCAP_APPLICATION` by using the `vcap` and `vcapFile`\noptions described below.\n\n\napi\n================================================================================\n\nThe `cfenv` package exports the following function:\n\n\n`getAppEnv(options)`\n--------------------------------------------------------------------------------\n\nGet the core bits of Cloud Foundry data as an object.\n\nThe `options` parameter is optional, and can contain the following properties:\n\n* `name` - name of the application\n\n  This value is used as the default `name` property of the returned object,\n  and as the name passed to\n  [the ports package `getPort()` function](https://www.npmjs.org/package/ports)\n  to get a default port.\n\n  If not specified, the name will looked for in the following places:\n\n  * the `name` property of the `VCAP_APPLICATION` environment variable\n  * the `name` property from the `manifest.yml` file in the current directory\n  * the `name` property from the `package.json` file in the current directory\n\n* `protocol` - protocol used in the generated URLs\n\n  This value is to override the default protocol used when generating\n  the URLs in the returned object.  It should be the same format as\n  [node's url `protocol` property](http://nodejs.org/api/url.html).\n  That is, it should end with a `:` character.\n\n* `vcap` - provide values for the `VCAP_APPLICATION` and `VCAP_SERVICES`\n  environment variable, when running locally.  The object can have\n  properties `application` and/or `services`, whose values are the same\n  as the values serialized in the respective environment variables.\n\n  Note that the `url` and `urls` properties of the returned object are not\n  based on the vcap `application` object, when running locally.\n\n  This option property is ignored if not running locally.\n\n* `vcapFile` - provide the same function as the `vcap` option, but instead of\n  setting the option value to an object, you set it to the name of a JSON\n  file, which will be parsed and used as the `vcap` option value is used,\n  as described above.\n\n  When both `vcap` and `vcapFile` options are provided, the values in `vcap`\n  are ignored.\n\n  This option property is ignored if not running locally.\n\n#### return value\n\nThe `getAppEnv()` function returns an object with the following properties:\n\n* `app`:      object version of `VCAP_APPLICATION` env var\n* `services`: object version of `VCAP_SERVICES` env var\n* `name`:     name of the application\n* `port`:     HTTP port\n* `bind`:     hostname/ip address for binding\n* `urls`:     URLs used to access the servers\n* `url`:      first URL in `urls`\n* `isLocal`:  false if a valid `VCAP_APPLICATION` env var was found, true otherwise\n\nThe returned object also has the following methods available:\n\n* `appEnv.getServices()`\n* `appEnv.getService(spec)`\n* `appEnv.getServiceURL(spec, replacements)`\n* `appEnv.getServiceCreds(spec)`\n\nIf no value can be determined for `port`, and the `name` property on the\n`options` parameter is not set and cannot be determined,\na port of 3000 will be used.\n\nIf no value can be determined for `port`, and the `name` property on the\n`options` parameter is set or can otherwise be determined,\nthat name will be passed to\n[the ports package `getPort()` function](https://www.npmjs.org/package/ports)\nto get a default port.\n\nThe protocol used for the URLs will be `http:` if the app\nis running locally, and `https:` otherwise; you can\nforce a particular protocol by using the `protocol` property\non the `options` parameter.\n\nWhen running in Cloud Foundry, the `url` and `urls` values will have\n`localhost` as their hostname, if the actual hostnames cannot be determined.\n\n\nAppEnv methods\n--------------------------------------------------------------------------------\n\nThe following methods are also available on the object returned by\n`cfenv.getAppEnv()`.\n\n\n\n**`appEnv.getServices()`**\n--------------------------------------------------------------------------------\n\nReturn all services, in an object keyed by service name.\n\nNote that this is different than the `services` property\nreturned from `getAppEnv()`.\n\nFor example, assume VCAP_SERVICES was set to the following:\n\n    {\n        \"user-provided\": [\n            {\n                \"name\": \"cf-env-test\",\n                \"label\": \"user-provided\",\n                \"tags\": [],\n                \"credentials\": {\n                    \"database\": \"database\",\n                    \"password\": \"passw0rd\",\n                    \"url\": \"https://example.com/\",\n                    \"username\": \"userid\"\n                },\n                \"syslog_drain_url\": \"http://example.com/syslog\"\n            }\n        ]\n    }\n\nIn this case, `appEnv.services` would be set to that same object, but\n`appEnv.getServices()` would return\n\n    {\n        \"cf-env-test\": {\n            \"name\": \"cf-env-test\",\n            \"label\": \"user-provided\",\n            \"tags\": [],\n            \"credentials\": {\n                \"database\": \"database\",\n                \"password\": \"passw0rd\",\n                \"url\": \"https://example.com/\",\n                \"username\": \"userid\"\n            },\n            \"syslog_drain_url\": \"http://example.com/syslog\"\n        }\n    }\n\n\n**`appEnv.getService(spec)`**\n--------------------------------------------------------------------------------\n\nReturn a service object by name.\n\nThe `spec` parameter should be a regular expression, or a string which is the\nexact name of the service.  For a regular expression, the first service name\nwhich matches the regular expression will be returned.\n\nReturns the service object from VCAP_SERVICES or null if not found.\n\n\n\n**`appEnv.getServiceURL(spec, replacements)`**\n--------------------------------------------------------------------------------\n\nReturns a service URL by name.\n\nThe `spec` parameter should be a regular expression, or a string which is the\nexact name of the service.  For a regular expression, the first service name\nwhich matches the regular expression will be returned.\n\nThe `replacements` parameter is an object with the properties used in\n[node's url function `url.format()`](http://nodejs.org/api/url.html#url_url_format_urlobj).\n\nReturns a URL generated from VCAP_SERVICES or null if not found.\n\nTo generate the URL, processing first starts with a `url` property\nin the service credentials.  You can override the `url` property in the\nservice credentials (if no such property exists), with a `replacements`\nproperty of `url`, and a value which is the name of the property in\nthe service credentials whose value contains the base URL.\n\nThat url is parsed with\n[node's url function `url.parse()`](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost)\nto get a set of initial url properties.\nThese properties are then overridden by entries in `replacements`, using the\nfollowing operation, for a given replacement `key` and `value`.\n\n     url[key] = service.credentials[value]\n\nThe URL `auth` replacement is a bit special, in that it's value should\nbe a two-element array of [userid, password], where those values are\nkeys in the service.credentials\n\nFor example, assume VCAP_SERVICES was set to the following:\n\n    {\n        \"user-provided\": [\n            {\n                \"name\": \"cf-env-test\",\n                \"label\": \"user-provided\",\n                \"tags\": [],\n                \"credentials\": {\n                    \"database\": \"database\",\n                    \"password\": \"passw0rd\",\n                    \"url\": \"https://example.com/\",\n                    \"username\": \"userid\"\n                },\n                \"syslog_drain_url\": \"http://example.com/syslog\"\n            }\n        ]\n    }\n\nAssume you run the following code:\n\n    url = appEnv.getServiceURL(\"cf-env-test\", {\n        pathname: \"database\",\n        auth:     [\"username\", \"password\"]\n    })\n\nThe `url` result will be `https://userid:passw0rd@example.com/database`\n\nNote that there **MUST** be a `url` property in the credentials,\nor replacement for it, in the\nservice, or the call will return `null`.  Also, because the `url` is parsed\nfirst with `url.parse()`, there will be a `host` property in the result, so\nyou won't be able to use the `hostname` and `port` values directly.  You\ncan **ONLY** set the resultant hostname and port with the `host` property.\n\nNote that `url.parse()` and the later `url.format()` calls to construct the\nresult, will not produce pleasing results for \"unusual\" URLs, especially\nthose which do not use `http:` or `https:` protocols.  The `url` `parse()`\nand `format()` methods will not be used though, if you have no replacement\nvalues, or the only replacement property is `url`, and so are safe to\nuse in that case.\n\nSince the `appEnv.getServiceURL()` method operates against the\n`appEnv.services` property, you can fudge this object if that makes your\nlife easier.\n\n**`appEnv.getServiceCreds(spec)`**\n--------------------------------------------------------------------------------\n\nReturns the `credentials` object of a service by name.\n\nThe `spec` parameter is the same as that used by the `appEnv.getServiceURL()`\nmethod.  If there is no service that matches the `spec` parameter, this method\nwill return `null`.\n\nIf there is a service that matches the `spec` parameter, the value of it's\n`credentials` property will be returned.  If for some reason, there is no\n`credentials` property on the service, an empty object - `{}` - will be\nreturned.\n\n\n\ntesting with Cloud Foundry\n================================================================================\n\nYou can push this project as a Cloud Foundry project to try it out.\n\nFirst, create a service name `cf-env-test` with the following command:\n\n    cf cups cf-env-test -p \"url, username, password, database\"\n\nYou will be prompted for these values; enter something reasonable like:\n\n    url\u003e      http://example.com\n    username\u003e userid\n    password\u003e passw0rd\n    database\u003e the-db\n\nNext, push the app with `cf push`.\n\nWhen you visit the site, you'll see the output of various cfenv calls.\n\n\nchanges\n================================================================================\n\n**1.2.4** - 2021/04/03\n\n- upgrade most dependencies, but not CoffeeScript, since the latest\n  version generates code that can't be run in older versions of node - [pr #50][]\n\n- change to call `yaml.load()` instead of `yaml.safeLoad()` since it's no\n  longer supported, noticed via an error message: - [pr #50][]\n\n  ```\n  Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default.\n  ```\n\n[pr #50]: https://github.com/cloudfoundry-community/node-cfenv/pull/50\n\n**1.2.3** - 2020/07/24\n\n- remove `.cfignore` file - [commit #02bb92d][]\n\n[commit #02bb92d]: https://github.com/cloudfoundry-community/node-cfenv/commit/02bb92dacf5f59244b188dae11fd2fe732c4940e\n\n**1.2.2** - 2019/03/26\n\n- handle ports package race condition by returning port 3000 - [pr #41][]\n\n[pr #41]: https://github.com/cloudfoundry-community/node-cfenv/pull/41\n\n**1.2.1** - 2019/03/25\n\n- upgrade js-yaml to avoid vulnerability - [pr #39][]\n\n[pr #39]: https://github.com/cloudfoundry-community/node-cfenv/pull/39\n\n**1.2.0** - 2019/02/21\n\n- use vcapFile port value if available - [pr #36][]\n- upgrade underscore from 1.8.x to 1.9.x - [pr #37][]\n- use `random-route:` instead of `${random-word}` in sample manifest - [pr #38][]\n\n[pr #36]: https://github.com/cloudfoundry-community/node-cfenv/pull/36\n[pr #37]: https://github.com/cloudfoundry-community/node-cfenv/pull/37\n[pr #38]: https://github.com/cloudfoundry-community/node-cfenv/pull/38\n\n**1.1.0** - 2018/04/18\n\n- add the `vcapFile` option - [issue #31][]\n\n[issue #31]: https://github.com/cloudfoundry-community/node-cfenv/issues/31\n\n**1.0.4** - 2017/01/13\n\n- fix to getServiceURL() with non-http URLs  - [issue #21][]\n\n[issue #21]: https://github.com/cloudfoundry-community/node-cfenv/issues/21\n\n**1.0.3** - 2014/10/02\n\n- fixes for compatibility with Diego - [issue #11][]\n\n[issue #11]: https://github.com/cloudfoundry-community/node-cfenv/issues/11\n\n**1.0.2** - 2014/09/29\n\n- delete a lingering `npm-debug.log` left behind\n- add `npm-debug.log` to `.gitignore`\n\n**1.0.1** - 2014/09/29\n\n- remove node_modules from .cfignore - [issue #8][]\n- updated package dependencies\n- changed README.md to correct sample service to cf-env-test\n- files in lib/ recompiled due to coffee-script update\n\n[issue #8]: https://github.com/cloudfoundry-community/node-cfenv/issues/8\n\n**1.0.0** - 2014/09/03\n\n- initial 1.0.0 release\n\n\ncontributing\n================================================================================\n\nSee the [CONTRIBUTING.md](CONTRIBUTING.md) doc for more information on\ncontributing to this project.\n\n\nlicense\n================================================================================\n\nApache License, Version 2.0\n\n\u003chttp://www.apache.org/licenses/LICENSE-2.0.html\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudfoundry-community%2Fnode-cfenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudfoundry-community%2Fnode-cfenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudfoundry-community%2Fnode-cfenv/lists"}