Node.js¶
Using Logfire in your Node.js script is straightforward. You need to get a write token, install the package, configure it, and use the provided API.
Let's create an empty project:
mkdir test-logfire-js
cd test-logfire-js
npm init -y es6 # This creates a package.json with `type: module` for ES6 support
npm install @pydantic/logfire-node
Then, create the following hello.js script in the directory:
import * as logfire from "@pydantic/logfire-node";
logfire.configure({
token: "your-write-token",
serviceName: "example-node-script",
serviceVersion: "1.0.0",
});
logfire.info(
"Hello from Node.js",
{
"attribute-key": "attribute-value",
},
{
tags: ["example", "example2"],
},
);
Run the script with node hello.js, and you should see the span appear in
the live view of your Logfire project.
A working example can be found in the examples/node directory of the logfire-js repository.