DEMO: Node.js
This chapter introduces how to call the APIs in Node.js.
Download DEMO: control-hub-api-demo-nodejs.zip.
DEMO Structure
control-hub-api-demo-nodejs
|
|-- httpUtils.js // encapsulates the get, post and upload method based on the HTTP module of Node.js.
|-- constant.js // constant
|-- xxxx.mwf // file uploaded by upload.js through invoking the /api/firmware/upload interface.
|-- get.js // requests data using GET
|-- upload.js // uploads file using POST
Requirements
- Operating System: macOS, Linux, or Windows
- Node.js Runtime: LTS releases (8.x and later)
Running Mode
- Navigate into the DEMO directory in the terminal.
cd control-hub-api-demo-nodejs
- Replace CONTROL_HUB_ADDRESS with the IP address of the Control Hub in constant.js.
- Run get.js.
node get
- Run upload.js.
node upload