Sample
detect-node 2.1.0: detect if code is running in node environment
Verified sample for npm detect-node 2.1.0: detect if code is running in node environment. The contract ran on node 22 · linux alpine/x64 · docker and passed.
sha256:4ac0fa8b7a486cc7cd27be3530094e1e8bfb26c79395415a97b5393cdcca367f
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-26 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-07 |
Case
HOW- Goal
- detect if code is running in node environment
- Packages
- Symbols
-
- detect-node
- Created
- 2026-08-26T09:03:16Z
Contract
- detect-node CommonJS export evaluates to a boolean
- detect-node evaluates to true when executed in Node.js environment
- detect-node ES module default export evaluates to true in Node.js
- wrapped helper function returns boolean true
- detect-node matches Object.prototype.toString check on global process object
- detect-node browser fallback entry exports false
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: detect if code is running in node environment
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/detect-node@2.1.0
Demonstrate these symbols/APIs:
- detect-node
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:61480310920d66dae1814660cf183b7b218fb90746ac69d65cd770ae95e62dbc","contract":["detect-node CommonJS export evaluates to a boolean","detect-node evaluates to true when executed in Node.js environment","detect-node ES module default export evaluates to true in Node.js","wrapped helper function returns boolean true","detect-node matches Object.prototype.toString check on global process object","detect-node browser fallback entry exports false"],"goal":"detect if code is running in node environment","kind":"HOW","packages":["pkg:npm/detect-node@2.1.0"],"schemaVersion":1,"symbols":["detect-node"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/detect-node@2.1.0"],"schemaVersion":1,"subject":"pkg:npm/detect-node@2.1.0","symbols":["detect-node"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-detect-node",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-detect-node",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"detect-node": "2.1.0"
}
},
"node_modules/detect-node": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz",
"integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==",
"license": "MIT"
}
}
}
{
"name": "sample-detect-node",
"version": "1.0.0",
"private": true,
"description": "Clean-room code sample for detect-node@2.1.0",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"detect-node": "2.1.0"
}
}
{
"schemaVersion": 1,
"goal": "detect if code is running in node environment",
"kind": "HOW",
"packages": [
"pkg:npm/detect-node@2.1.0"
],
"symbols": [
"detect-node"
]
}
const isNode = require('detect-node');
/**
* Checks if the current runtime execution environment is Node.js.
*
* @returns {boolean} True if running in Node.js environment, false otherwise.
*/
function checkIsNode() {
return isNode;
}
module.exports = {
isNode,
checkIsNode
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import isNodeEsm from 'detect-node';
const require = createRequire(import.meta.url);
const isNodeCjs = require('detect-node');
const { isNode, checkIsNode } = require('../src/index.js');
const browserExport = require('detect-node/browser.js');
async function testAll() {
// 1. detect-node CommonJS export evaluates to a boolean
assert.equal(typeof isNodeCjs, 'boolean', 'detect-node CJS export must be boolean');
// 2. detect-node evaluates to true when executed in Node.js environment
assert.equal(isNodeCjs, true, 'detect-node CJS export must be true in Node.js');
// 3. detect-node ES module default export evaluates to true in Node.js
assert.equal(typeof isNodeEsm, 'boolean', 'detect-node ESM default export must be boolean');
assert.equal(isNodeEsm, true, 'detect-node ESM export must be true in Node.js');
// 4. wrapped helper function returns boolean true
assert.equal(typeof checkIsNode, 'function', 'checkIsNode must be a function');
assert.equal(checkIsNode(), true, 'checkIsNode() must return true in Node.js');
assert.equal(isNode, true, 'exported isNode must be true');
// 5. detect-node matches Object.prototype.toString check on global process object
const expectedProcessCheck = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
assert.equal(isNodeCjs, expectedProcessCheck, 'detect-node value must match Object.prototype.toString process check');
// 6. detect-node browser fallback entry exports false
assert.equal(browserExport, false, 'detect-node browser entry must export false');
console.log('All detect-node contract tests passed.');
}
testAll().catch((err) => {
console.error('Contract test failure:', err);
process.exit(1);
});
Origin Seeder
anonymous