{"id":9726,"date":"2015-10-28T08:48:11","date_gmt":"2015-10-28T13:48:11","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=9726"},"modified":"2020-11-18T14:53:47","modified_gmt":"2020-11-18T20:53:47","slug":"node-js-examples","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/mlinux\/mlinux-software-development\/node-js-examples\/","title":{"rendered":"Node.js Examples"},"content":{"rendered":"<p><strong>NOTE<\/strong>: Node.js is not available in<em>\u00a0<\/em>mLinux 5.3.x and above.<\/p>\n<p><strong>Pushing data to M2X Cloud<\/strong><\/p>\n<pre class=\"brush:js\">    \r\n    var http = require(\"http\");\r\n\r\n    var device_id = \"&lt;DEVICE-ID&gt;\";\r\n    var m2xKey = \"&lt;M2X-KEY&gt;\";\r\n    var stream = \"&lt;STREAM-NAME&gt;\";\r\n    var data = { \"value\": 30 };\r\n\r\n    var content = JSON.stringify(data);\r\n\r\n    var options = {\r\n        method : 'PUT',\r\n        host : 'api-m2x.att.com',\r\n        path : '\/v2\/devices\/' + device_id + \"\/streams\/\" + stream + \"\/value\",       \r\n        headers : {\r\n            'Content-Type' : 'application\/json',\r\n            'Content-Length' : content.length,\r\n            'X-M2X-KEY' : m2xKey\r\n        }\r\n    };\r\n\r\n    var req = http.request(options, function(res) {\r\n        res.setEncoding('utf8');\r\n        res.on('data', function(chunk) {\r\n            console.log('BODY: ' + chunk);\r\n        });\r\n    });\r\n\r\n    req.on('error', function(err) {\r\n        console.error(\"post error: \", err.message);\r\n    });\r\n\r\n    \/\/ post the data\r\n    req.write(content);\r\n    req.end();<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: Node.js is not available in\u00a0mLinux 5.3.x and above. Pushing data to M2X Cloud var http = require(&#8220;http&#8221;); var device_id = &#8220;&lt;DEVICE-ID&gt;&#8221;; var m2xKey = &#8220;&lt;M2X-KEY&gt;&#8221;; var stream = &#8220;&lt;STREAM-NAME&gt;&#8221;; var data = { &#8220;value&#8221;: 30 }; var content = JSON.stringify(data); var options = { method : &#8216;PUT&#8217;, host : &#8216;api-m2x.att.com&#8217;, path : &#8216;\/v2\/devices\/&#8217; + [&hellip;]<\/p>\n","protected":false},"author":1337,"featured_media":0,"parent":9192,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-9726","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/1337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=9726"}],"version-history":[{"count":7,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9726\/revisions"}],"predecessor-version":[{"id":28535,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9726\/revisions\/28535"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9192"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=9726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}