# Node.js

Source: https://docs.interop.io/desktop/getting-started/how-to/interop-enable-your-apps/nodejs/index.html

## Referencing

The [`@interopio/desktop`](https://www.npmjs.com/package/@interopio/desktop) library is available as an NPM package which you can include as a dependency in your project and import in your code.

To install the `@interopio/desktop` library, execute the following command:

```cmd
npm install @interopio/desktop
```

You can now import the factory function exposed by the library and start interop-enabling your apps:

```javascript
const IODesktop = require("@interopio/desktop");
```

## Initialization

If your Node.js app is started by **io.Connect Desktop**, it isn't required to pass authentication information in the optional configuration object passed to the factory function:

```javascript
const IODesktop = require("@interopio/desktop");

// This will prevent the app from exiting when io.Connect is initialized.
// Remove in real apps.
setTimeout(()=>{
	console.log("Done.");
}, 10000);

const initializeIOConnect = async () => {
    // Optional configuration for initializing the library.
    const config = { appManager: "full" };

    // Use the object returned by the factory function to access the io.Connect APIs.
    const io = await IODesktop(config);

    // Here io.Connect is initialized and you can access all io.Connect APIs.

    console.log(`io.Connect version: ${io.version}`);
};

initializeIOConnect().catch(console.error);
```

## App Definition

To add your Node.js app to the [io.Connect launcher](https://docs.interop.io/desktop/capabilities/launcher/index.md), you must create a JSON [app definition](https://docs.interop.io/desktop/developers/configuration/application/index.md) file for it. Place this file in the `<installation_location>/interop.io/io.Connect Desktop/UserData/<ENV>-<REG>/apps` folder where `<ENV>-<REG>` represents the environment and region of **io.Connect Desktop** (e.g., `DEMO-INTEROP.IO`).

The following is an example definition of a Node.js app:

```json
{
    "name": "node-server",
    "type": "node",
    "service": true,
    "details": {
        "path": "%IO_CD_ROOT_DIR%/PathToMyServer/index.js"
    }
}
```

The `"name"`, `"type"`, and `"path"` properties are required and `"type"` must be set to `"node"`. The `"path"` property points to a JavaScript file that **io.Connect Desktop** will execute in a Node.js environment.

> ℹ️ *For details on how to configure a remotely hosted Node.js app, see the [Developers > Configuration > Application](https://docs.interop.io/desktop/developers/configuration/application/index.md#app_definition-nodejs-remote_apps) section.*
