Skip to main content

Your First Node App

Welcome to the Neurosity SDK documentation site. To begin, you'll need to set up an account one time with Neurosity via Learn how to create an account with Neurosity Developer Console.


To download the necessary tools, clone the repository, and install dependencies via npm, you need network access.


You'll need the following tools:

Install and build all of the dependencies using NPM


We'll be using VSCode to program this tutorial. For a little added fun, we recommend adding the Neurosity VSCode extension to track your flow state while programming. Check out our guide to installing and getting started with VSCode and the Neurosity extension.

Tutorial Repository

Want to see the complete project before reading anymore? You can view all the code from this project in it's repository on Github.

Setup your Project

Hello World Folder

Create a new folder called hello-world

mkdir hello-world

Enter into the directory and initialize the npm project.

cd hello-world
npm init

You'll need to run through the initial questions:

package name: (hello-world)
version: (1.0.0)
description: My first application using the Neurosity SDK
entry point: (index.js)
test command:
git repository:
keywords: neurosity
author: Hans Berger
license: (ISC) MIT

Initial set up of NPM project

Next, you'll want to launch a VSCode window for the newly created project.

code .

Working in VSCode

You'll need to launch a terminal window inside VS Code, you may toggle the terminal with CTRL+~.

Toggle command line

To create a new file, you may select the new file button.

Highlighting new file button in vscode

Go ahead and make a new file called index.js, we'll use it soon as the base of our new project.

Created a new file called index.js

Adding the Neurosity SDK to a Node Project

Add .gitignore file

The first thing we want to do is add a file called .gitignore to tell git to ignore certain files. Add another file to the root directory called .gitignore, then add the following:


On MacOS, we'll go ahead and add another commonly ignored file:


Add a .gitignore file with node_modules

Adding node_modules will help VS Code run a little bit better because we're telling it that we don't need to track anything in that folder.

Install Dependencies

The first dependency we need to install the Neurosity SDK. We'll end up using some environment variables from a .env file, so go ahead and install another dependency for that as well. From the command line, enter:

npm install @neurosity/sdk dotenv

Install dependencies using npm install in the terminal

Add Dependencies to index.js

Importing libraries in Node is quite simple, all you have to do is add the following to the top of your index.js file:

const { Neurosity } = require("@neurosity/sdk");

Add dependencies to the index.js file

Add start script to package.json

Now head over to the file called package.json. The package.json is at the core of every Node package. Ignore the file called package-lock.json, it's automatically generated.

Find the section called "scripts" and add a property called "start" that will start the node process:

"start": "node index.js"

Your package.json will look like below once added:

"name": "hello-world",
"version": "1.0.0",
"description": "My first application using the Neurosity SDK",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"keywords": ["neurosity"],
"author": "Hans Berger",
"license": "MIT",
"dependencies": {
"@neurosity/sdk": "^3.8.0",
"dotenv": "^8.2.0"

Run the project from the CLI

Navigate back to the terminal and run npm start to make sure the project runs without any errors.

npm start

You should see the program run and exit successfully.

Ran our node program with no errors

Add Authentication

At this point you will need to have created an account with and claimed your device.

Get variables from .env file

We'll first attempt to get our environment variables to show what happens when they are not there at runtime. Add the following code to pull the deviceId, email and password from the enviroment variables:

const deviceId = process.env.DEVICE_ID || "";
const email = process.env.EMAIL || "";
const password = process.env.PASSWORD || "";

To verify that the variables are not blank, we could add a function to check for that and quit the program if so. Add the following function to your program next:

const verifyEnvs = (email, password, deviceId) => {
const invalidEnv = (env) => {
return env === "" || env === 0;
if (invalidEnv(email) || invalidEnv(password) || invalidEnv(deviceId)) {
"Please verify deviceId, email and password are in .env file, quitting..."
verifyEnvs(email, password, deviceId);

console.log(`${email} attempting to authenticate to ${deviceId}`);

Now, if we run our program, we should see an error print out! Run with npm start from the CLI.

Ran our node program with no envs found error

Add .env file

Next, we'll add a .env to store our deviceId, login, and password. Add a new file called .env and add your deviceId, email, and password. Learn how to find your device ID.


Created a new file called .env

Now, if we run our program, we should see a success message print out, informing us that our variables have been extracted successfully.

Pulled out three variables from .env

Instantiate the Neurosity class

We can then use the deviceId to instantiate a new Neurosity by adding the following line to our file.

const neurosity = new Neurosity({

Add async login

We need to use an async/await paradigm for authenticating to the device. Go ahead and create an async function called main to the index.js file.

const main = async () => {
await neurosity
.catch((error) => {
throw new Error(error);
console.log("Logged in");


Then run the program with npm start in the CLI. If all worked, then you should see:

Made a function that authenticated with Neurosity

Add Subscriptions

Calm Subscription

Now that you are authenticated, print out hello world when you're calm increases past 0.3, a significant number.

Add the following code to your main() function after login.

neurosity.calm().subscribe((calm) => {
if (calm.probability > 0.3) {
console.log("Hello World!");

Your index.js file is now ready to print Hello World!

Add code to subscribe to the calm score

Kinesis Training

Head over to the Developer Console and train Left Hand Pinch. Learn how to train an imagined movement thought. Do at least 15 trials.

When we write code to interact with the Neurosity SDK, we use camel case, so Left Hand Pinch in code is leftHandPinch.

Now that the leftHandPinch thought is trained, you'll be able to load it into your device for use.

Kinesis Subscription

In the index.js file we can remove the calm subscription from above and replace it with the code below.

Check out the Kinesis guide or Kinesis API docs.

neurosity.kinesis("leftHandPinch").subscribe((intent) => {
console.log("Hello World!");

Your index.js file should look like:

Add kinesis code to index.js


Developing with the Neurosity SDK can be a lot of fun! There are two main types of thought processes that Neurosity devices can detect: intent and background. The foreground we consider to be the kinesis() where you're intending to do something and the background is calm() or focus() that occurs in the background of the mind.

Dive into development

We're looking for talented developers to help us improve the kinesis training. So, head over to the training guide and learn how to build your own training module.

If you're looking for exact API references, check out the API section of these docs!