modified by joseph at www.ittraining.com.tw
Example Node.js express app that talks to the mbed Device Connector.
You need to have Node.js and npm installed.
To check if you have them installed, open a terminal or command prompt and run the following commands:
node --version
npm --version
If you see an number output similar to x.x.x for each command, then they are both installed and you can continue to the next section.
To install on Windows or Mac, you can download the installer here.
To install on Linux, you can use a package manager. Instructions for installing Node.js on your distribution can be found here
This example assumes that you have an mbed Client connected to mbed Device Connector.
If you have an mbed, you can use the mbed Client Example.
Before running the app, you need to set some config options. This is done through environment variables or by creating a .env
file in the root of the project.
The following variables are available to be configured:
- ACCESS_KEY - (required) Set this to your Access Key you created in mbed Device Connector. If you do not have an Access Key, see the section Creating an Access Key
- PORT - Set this to override the default port for the app. The default port is 8080.
The .env
file format is as follows:
ACCESS_KEY=<My Access Key>
PORT=8080
See the dotenv project page for more information on .env
configuration.
Once you've configured the app, you need to install its dependencies. Open a terminal or command prompt and run this command:
npm install
You can now run the app by using the following command:
node app.js
You should receive the following output:
mbed Device Connector Quickstart listening at http://localhost:8080
Copy and paste the printed URL into your browser and you should see a page listing all of your connected mbed Clients.
See the instructions in the mbed Client example testing section to update the endpoint's button resource.
- Login to your account at https://connector.mbed.com.
- Under My applications, click Access keys.
- Click Create New Access Key. When prompted, enter a name for the access key (ex. "Quickstart") and click ADD.
- Copy the access key you just created and use it when you're configuring your app.