Gathering detailed insights and metrics for @gustavnikolaj/node-invariant
Gathering detailed insights and metrics for @gustavnikolaj/node-invariant
Gathering detailed insights and metrics for @gustavnikolaj/node-invariant
Gathering detailed insights and metrics for @gustavnikolaj/node-invariant
npm install @gustavnikolaj/node-invariant
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
10 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 29, 2020
Latest Version
1.0.0
Package Id
@gustavnikolaj/node-invariant@1.0.0
Unpacked Size
11.41 kB
Size
4.13 kB
File Count
13
NPM Version
6.14.6
Node Version
12.18.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
All other invariant-style modules I have found are optimized for the browser and
will typically use process.env.NODE_ENV === 'production'
as a hook to get
their minifiers to remove the expensive debug code. This makes sense for
frontend code where you don't need the explanations in the messages, but it is
really annoying for server code where you don't need to optimize that much for
size - it just makes debugging harder.
The only one I found which didn't have this problem gave polluted stack traces, so I just quickly wrangled this together.
$ npm install @gustavnikolaj/node-invariant
1const invariant = require('@gustavnikolaj/node-invariant') 2 3invariant(myCondition, 'My invariant message'); 4 5// if myCondition is falsy: 6// 7// InvariantViolation: My invariant message 8// at ~/Projects/my-app/test.js
The core assert module almost works just as well, but it generates too noisy errors and have a lot of extra complexity going on.
The reason you would use a module like this is not for errors facing the caller of your web application or REST API, it's for other developers, or poor OPS-people trying to get your application to run.
If you have required secrets that must be passed in as environemnt variables, you could use this module:
1// filename: config.js 2 3const invariant = require('@gustavnikolaj/node-invariant'); 4 5invariant( 6 typeof process.env.DB_PASS === 'string' && process.env.DB_PASS.length, 7 'Missing environment variable DB_PASS' 8); 9 10module.exports = { 11 database: { 12 // ... 13 password: process.env.DATABASE_PASSWORD 14 } 15};
If the person trying to start your application forgot passing in the DB_PASS
variable, they will now get a nice error:
InvariantViolation: Missing environment variable DB_PASS
at Object.<anonymous> (~/Projects/my-app/start-server.js:1:14)
The same error but with assert would look like this:
AssertionError [ERR_ASSERTION]: Missing environment variable DB_PASS
at Object.<anonymous> (/Users/John/Projects/my-app/start-server.js:1:14)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/10 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
19 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More