> ## Documentation Index
> Fetch the complete documentation index at: https://docs.joinmassive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Windows JS

> Integrate Massive embedded SDK into your Windows Electron or Node.js application with this guide.

## Example code

```javascript theme={null}
const { app } = require('electron');
const massive = require('./3rdparty/massive');

...

app.whenReady().then(async () => {
  if (massive.isSupported()) {
    await massive.init(apiToken);
    await massive.start();

    const isStarted = await massive.isStarted();

    if (isStarted) await massive.stop();
  }
});

...

app.on('will-quit', (event) => {
  event.preventDefault();
  massive.cleanUp().finally(() => app.exit());
});
```

## Getting started

1. Download the [latest embedded SDK package][3].

2. Extract the package to your folder of choice.

3. Copy the extracted `js\massive` folder into your app, for example to
   `3rdparty\massive`.

4. In your app's main process, import the SDK:

   ```javascript theme={null}
   // Importing in JavaScript:
   const massive = require('./3rdparty/massive');
   ```

5. Start and wait till the SDK is ready by calling the `init` function:

   ```javascript theme={null}
   // Starting in JavaScript:
   await massive.init(apiToken);
   ```

6. When the user opts in, call the `start` function:

   ```javascript theme={null}
   // Opting in in JavaScript:
   await massive.start();
   ```

7. Before your app quits, call the `cleanUp` function:

   ```javascript theme={null}
   // Cleaning up in JavaScript:
   await massive.cleanUp();
   ```

8. When you package your app, keep the SDK's `prebuilds` folder out of
   `app.asar`. With electron-builder, add
   `"asarUnpack": ["3rdparty/massive/prebuilds/**"]` to the `build` section of
   `package.json`.

See the [API reference][6] for detailed info and optional SDK functionality.

## Sample apps

See the `README.md` file, `docs` folder and `samples` folder in the
[embedded SDK package][7]. The samples demonstrate how to integrate the SDK into
your project and use its functionality.

* `MassiveEmbeddedMinimal` is a simple Electron application that demonstrates
  how to integrate the SDK into a JavaScript project.
* `MassiveEmbeddedElectron` is a complete Electron application that also
  demonstrates the tray, usage statistics and an installer.

## API reference

### Types

**`class MassiveError extends Error`**

The error the SDK's functions reject with when a call fails.

**Properties**

**`code`** `ERR_MASSIVE_` followed by the status, such as
`ERR_MASSIVE_INTERNAL_ERROR`, or `ERR_MASSIVE_UNAVAILABLE` when the SDK can't run
in this process.

**`status`** The status of the SDK: `INVALID_ARGS`, `UNINITIALIZED`,
`INITIALIZING` or `INTERNAL_ERROR`.

**`operation`** The function that failed, such as `start`.

***

### Functions

Every function but `isSupported`, `getUnsupportedReason` and `getVersion`
returns a promise, which rejects with a `MassiveError` when the call fails.

**`isSupported(): boolean`**

Queries whether the SDK can run in this process.

**Return value**

`true` if the SDK can run in this process.

***

**`getUnsupportedReason(): string | null`**

Queries why the SDK can't run in this process.

**Return value**

The reason as a sentence, or `null` when the SDK can run.

***

**`getVersion(): string`**

Returns the version of the Massive SDK.

**Return value**

The version of the Massive SDK in the format `major.minor.patch`.

***

**`setDataBasePath(path: string): Promise<void>`**

Sets the folder for the SDK's data and log. Call it before the `init` function.

**Parameters**

**`path`** An absolute path, or `''` for the default folder.

***

**`init(apiToken: string): Promise<void>`**

Initializes the Massive SDK, pending user opt-in, attributed to your API token.

**Parameters**

**`apiToken`** A unique developer identifier obtained from the [applications](https://sdk.joinmassive.com/applications) page.

***

**`start(): Promise<void>`**

Allows computing resources to be opportunistically consumed. The user must agree
to easy-to-understand terms of the exchange you’re offering before you call this
function.

***

**`stop(): Promise<void>`**

Disallows computing resources to be consumed.

***

**`isStarted(): Promise<boolean>`**

Queries whether the node runs.

**Return value**

`true` while the node runs.

***

**`isMonetizing(minutes?: number): Promise<boolean>`**

Queries whether the node runs and has relayed traffic since it started, or within
the last `minutes` minutes.

**Parameters**

**`minutes`** How far to look back, in minutes. `0`, the default, means since the
node started.

**Return value**

`true` if the node has relayed traffic.

***

**`getComputationStatistics(options?: StatisticsOptions): Promise<StatisticSample[]>`**

Returns the usage statistics over a period, cut into samples.

**Parameters**

**`options.from`**, **`options.to`** The period, as Dates or milliseconds since
1970\. By default, the last 24 hours.

**`options.samples`** How many samples to cut the period into. By default, 24.

**Return value**

One sample per part of the period, with `timestamp`, `cpuUsage`,
`totalCpuUsage`, `memoryUsage`, `totalMemoryUsage`, `gpuUsedTotal` and
`networkTraffic`.

***

**`cleanUp(): Promise<void>`**

De-initializes and releases all resources acquired by Massive. Call it before
your app quits.

[3]: https://sdk.joinmassive.com/downloads

[6]: #api-reference

[7]: #getting-started


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.