Node.js Token Generator Code

Example Node.js code to generate an API Token

var crypto = require('crypto');

var secret = 'testsecret';
var timestamp = new Date().getTime();
var ip = '192.168.1.1';

var tokenString = secret + ':' + ip + ':' + timestamp;

var hmac = crypto.createHmac('md5', secret);
hmac.setEncoding('hex');

hmac.end(tokenString, function () {
var token = hmac.read();
console.log(token);
});

Example

Running this code with the timestamp 1424082443000 yields the value:

092268a2d33f46bf990676efdab34d2d

Last updated

Was this helpful?