Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
node-env-type
Advanced tools
Easy detection of NodeJS environment type from NODE_ENV
variable.
This library is 100% compatible with the standard development
/test
/production
approach,
with a friendlier interface, while also supporting a more verbose syntax, to allow for
a flexible environment configuration.
$ npm i node-env-type
import {env} from 'node-env-type';
if(env.isDev) {
// this is a DEV environment
}
const {env} = require('node-env-type');
if(env.isProd) {
// this is a PROD environment
}
Table below explains available flags and when they are set.
Flag | Environment | Condition |
---|---|---|
isDev | Development | NODE_ENV includes dev (case-insensitive) |
isUAT | User Acceptance Testing | NODE_ENV includes uat (case-insensitive) |
isSIT | System Integration Testing | NODE_ENV includes sit (case-insensitive) |
isCI | Continuous Integration | NODE_ENV includes ci (case-insensitive) |
isTest | General Testing | NODE_ENV includes any of: test , tst , uat , sit , ci (case-insensitive) |
isProd | Production | NODE_ENV includes prod (case-insensitive), or not set at all. |
Flags are tested in the order as shown in the table, to use only the first one found, in case there's a conflict.
isTest
- set not only when NODE_ENV
includes test
or tst
, but also when isUAT
, isSIT
or isCI
is set, because all those environments are essentially for testing.isProd
- set not only when NODE_ENV
includes prod
, but also when NODE_ENV
is not set at all,
i.e. when environment is not configured, we should assume it to be production.NODE_ENV
is set to something we cannot recognize at all, each flag is set to false
.The only API available other than the environment flags is function refresh
, in case you want
to refresh flags from the environment without restarting the process.
import {env} from 'node-env-type';
if(env.refresh()) {
// successfully recognized the environment;
// each flag updated from NODE_ENV
} else {
// failed to recognize the environment;
// each flag is set to false
}
And if, for some reasons, you decide to read configuration from a different place, rather than
the standard NODE_ENV
, you can pass such optional string to the function:
const otherVar = 'dev1.pc'; // just some other value
if(env.refresh(otherVar)) {
// successfully recognized the environment;
// each flag updated from otherVar
} else {
// failed to recognize the environment;
// each flag is set to false
}
FAQs
NodeJS Environment Type detection.
We found that node-env-type demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.