NodeFox

Lesson 7 · Intermediate

Use Code for exact checks

Calculate the purchase-order discrepancy with a reproducible JavaScript fixture.

1:57 video guide + written guide

Source-based instructional visualization · synthetic examples · AI narration. This explains configuration and behavior; it is not a recording of a verified live run.

Jump to a chapter

Before you start

A signed-in NodeFox workspace. Use synthetic data and prepare outputs before enabling external writes.

  1. 01Define the input

    Route a structured order object to Code input slot 1. JavaScript reads this as inputs.get(0). The example uses integer cents to avoid floating-point ambiguity and requires a positive whole-number quantity.

  2. 02Write the calculation

    Validate quantity, orderUnitCents and contractUnitCents before calculating quantity times the difference between the two prices. Write the result to outputs.set(0, result). This is output slot 1 in the visual graph.

  3. 03Run local fixtures

    Download the academy example code and tests. Run node --test public/examples/academy/checks.test.mjs from the website repository. These tests verify the pure calculation, not a live NodeFox execution. Paste the Code-node version into a learning network to test the actual graph separately.

  4. 04Inspect and route

    The 20-unit example at 95 dollars versus 98 dollars produces 6,000 cents, or 60 dollars. Route a non-zero difference for human review. Do not connect the calculation directly to an irreversible business action.

Example configuration or input

const order = inputs.get(0);
// Validate required fields before calculating.
const differenceCents = order.quantity *
  (order.contractUnitCents - order.orderUnitCents);
outputs.set(0, { ...order, differenceCents });

Expected result

20 × (9800 − 9500) = 6000 cents.

If the result is wrong

inputs[0] and outputs[0] are not the Map interface. Use get and set. Validate strings, negative quantities and missing fields.

Reproduce the exact checks

Save both .mjs files and the two Code-node .js files in the same folder and run node --test checks.test.mjs. These test the calculation independently; they do not execute the NodeFox runtime.