# windsor-node

> Integrate user and event capture with Node applications

Latest version **1.0.0** (published 2020-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install windsor-node
pnpm add windsor-node
yarn add windsor-node
bun add windsor-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-07-17 |
| First published | 2019-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 8 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 (+26 in 2 direct dependencies) |
| Install scripts | no |
| Author | Windsor |
| Maintainers | pranaygp |
| Keywords | analytics, stats, windsor.io, windsorio, windsor, client, driver |

## Links

- npm: https://www.npmjs.com/package/windsor-node
- Repository: https://github.com/windsorio/node
- Homepage: https://github.com/windsorio/node#readme
- Issues: https://github.com/windsorio/node/issues
- npm.io page: https://npm.io/package/windsor-node

## Dependencies (8)

- [ms](https://npm.io/package/ms.md) 2.1.2
- [md5](https://npm.io/package/md5.md) 2.2.1
- [uuid](https://npm.io/package/uuid.md) 8.2.0
- [axios](https://npm.io/package/axios.md) 0.19.2
- [axios-retry](https://npm.io/package/axios-retry.md) 3.1.8
- [lodash.isstring](https://npm.io/package/lodash.isstring.md) 4.0.1
- [remove-trailing-slash](https://npm.io/package/remove-trailing-slash.md) 0.1.0
- [@segment/loosely-validate-event](https://npm.io/package/@segment/loosely-validate-event.md) 2.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-07-17
- 0.1.0 — 2020-07-16
- 0.0.3 — 2019-08-15
- 0.0.2 — 2019-08-07
- 0.0.1 — 2019-08-06

## README

# windsor-node

Send data for [Windsor.io](https://windsor.io) from Node

<div align="center">
  <img src="https://cdn.windsor.io/github/windsor-node/windsor.png"/>
</div>

## Get started

1. **Create a [Windsor](https://windsor.io) Account**
2. [**Setup the Node source**](https://app.windsor.io/sources)
3. **Create Users** on Windsor
   - With `windsor-node`, call `windsor.user(...)` everytime a new user signs up or data about a user changes to keep things updated
4. **Track Events**
   - You'll want to see every important event or issue your user runs into. Call `windsor.event(...)` for every event you want to know a user has taken. You can setup alerts and more from [Windsor](https://windsor.io)

Read the docs [here](https://docs.windsor.io/docs/analytics).

### Why?

You care about your users. You probably already have a slack channel filling up with important events, or you search through logs to see what your users are upto. Windsor is a better way. Track the users and events you care about to Windsor so your company can more easily manage and understand your user behavior.

For example, you can create a new Windsor user from any Node app:

```js
windsor.user({
  userId: "01nc83ns",
  traits: {
    name: "Pranay Prakash",
    email: "hey@windsor.io",
    company: "windsor",
    posts: 42,
  },
});
```

And track events you'd like to know your users took

```js
windsor.event({
  userId: "01nc83ns",
  event: "Post Created",
  properties: {
    title: "Getting Started",
    private: false,
  },
});
```

Then follow the user on [Windsor](https://windsor.io)

<div align="center">
  <img src="https://cdn.windsor.io/github/windsor-node/follow.png"/>
</div>

## Installation

```bash
$ yarn add windsor-node
```

## Usage

```js
const Windsor = require("windsor-node");

const windsor = new Windsor("token");

windsor.user({
  userId: "user id",
  traits: {
    name: "user name",
    email: "user email",
  },
});

windsor.event({
  event: "event name",
  userId: "user id",
});
```

### Advanced Usage

`windsor-node` batches and sends multiple events together to improve performance on production systems. When using `windsor-node` on a serverless/lambda environment like AWS Lambda, [Vercel](https://vercel.com/) or [Serverless](https://www.serverless.com/), you need to ensure that all events are sent before responding to the request.

```javascript
const Windsor = require("windsor-node");
const windsor = new Windsor("token");

exports.handler = async (event) => {
  let greeting = "";
  if (event.queryStringParameters && event.queryStringParameters.greeting) {
    console.log("Received greeting: " + event.queryStringParameters.greeting);
    greeting = event.queryStringParameters.greeting;
  }

  // A promise is returned, but instead of using await here
  // we can send multiple analytics events and then await a single
  // call to windsor.flush() before returning the response
  windsor.event({
    event: "Sent Greeting",
    properties: {
      greeting,
    },
  });

  const message = `${greeting} World.`;
  const responseBody = { message };
  const response = {
    statusCode: 200,
    body: JSON.stringify(responseBody),
  };

  await windsor.flush();
  return response;
};
```

## Documentation

Documentation is available at [https://docs.windsor.io/docs/analytics](https://docs.windsor.io/docs/analytics)

## License

Copyright &copy; 2020 Windsor Software Inc. \<team@windsor.io\>

See the LICENSE file for details and see the SEGMENT_LICENSE file attribution to the [Segment Library](https://github.com/segmentio/analytics-node) this was based off.

---
_Source: https://npm.io/package/windsor-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
