npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

client-trace

v1.0.4

Published

"A versatile library that combines header data with optional device and browser attributes to enhance accuracy. Offers customizable logic for ID generation, making it adaptable to diverse use cases."

Downloads

217

Readme

Client Trace

Client Trace is a lightweight and efficient npm package for generating a unique identifier for user identification in HTTP requests. It leverages request headers, socket data, and optional DNS lookups for enhanced accuracy and adaptability. This package is ideal for tracking users or devices in both server-side and client-side environments.


Features

  • Accurate Identification: Combines HTTP headers and socket information to generate a unique ID.
  • Force Mode: A third parameter allows forcing DNS lookups to retrieve the user's IP address.
  • Lightweight and Simple: Easy to integrate into any Node.js application.
  • Customizable: Works with both server and client-side HTTP requests.

Installation

Install the package using npm:

npm install client-trace

Usage

Basic Example

Here's an example of how to use Client Trace in a Node.js application:

const { uniqueUserId } = require("client-trace");

// Example HTTP request data
const headers = {
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
  "x-forwarded-for": "203.0.113.195",
  "sec-ch-ua-platform": '"Windows"',
};
const socket = {
  remoteAddress: "203.0.113.1",
};

// Generate a unique user ID
const uniqueId = await uniqueUserId(headers, socket);
// or you can add req.headers, req.socket

console.log("Unique ID:", uniqueId);

With Force Mode

To enforce DNS lookups for IP resolution, pass true as the third parameter:

const uniqueId = await uniqueUserId(headers, socket, true);

console.log("Unique ID:", uniqueId);

API

uniqueUserId(headers, socket, force)

Parameters:

  1. headers (Object, Required):

    • The request headers sent by the user. Must include common headers like user-agent, x-forwarded-for, etc.
  2. socket (Object, Required):

    • The socket object of the HTTP request. Must include remoteAddress for identifying the client IP.
  3. force (Boolean, Optional):

    • If true, the function will attempt to resolve the IP using DNS servers, even if it’s already available in headers or socket.

Returns:

An object containing the following properties:

  • uniqueId: The generated unique identifier.

Example Output

"0d7c44c95d89d795b54dfa381ebbd2cc42635fd6383f6e28ddace29bf771d3d6";

Error Handling

If the function encounters an error (e.g., invalid headers, DNS failure), it will log the error and return undefined.


Use Cases

  1. User Tracing: Generate unique IDs for identifying users across sessions or devices.
  2. Security: Enhance logging for security and fraud detection.
  3. Analytics: Trace devices or browsers accessing your application.

⚠️ Note on Version 1.0.0

This is the first version of the library, and there are known limitations:

  • The library may generate the same unique ID for devices accessing the application over the same IP address or network connection.
  • This behavior occurs due to the current logic relying on headers, IP, and socket information, which can be identical for users on shared networks or devices.

I am actively working to enhance the ID generation logic in future versions to address these limitations. Contributions, feedback, and suggestions are welcome!


Contributions

Feel free to contribute to Client Trace by creating issues or submitting pull requests on the GitHub repository.