Skip to content

Instantly share code, notes, and snippets.

@ten2net
Last active October 17, 2018 10:57
Show Gist options
  • Save ten2net/3a5a836dd76692a1c380a41c6ebc7006 to your computer and use it in GitHub Desktop.
Save ten2net/3a5a836dd76692a1c380a41c6ebc7006 to your computer and use it in GitHub Desktop.
var request = require('request');
var host = 'localhost:8080';
var username = 'tenant@thingsboard.org';
var password = 'tenant';
var user = {
'username': username,
'password': password
};
var options = {
method: 'post',
url: 'http://' + host + '/api/auth/login',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(user),
};
request(options, function(error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
@ten2net
Copy link
Author

ten2net commented Oct 17, 2018

Go to directory of your project

mkdir TestProject
cd TestProject

Make this directory a root of your project (this will create a default package.json file)

npm init --yes

Install required npm module and save it as a project dependency (it will appear in package.json)

npm install request --save

Create a test.js file in project directory with code from package example

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body); // Print the google web page.
  }
});

Your project directory should look like this

TestProject/
- node_modules/
- package.json
- test.js

Now just run node inside your project directory

node test.js 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment