Last active
August 14, 2017 16:30
-
-
Save Smithx10/f7d54c02760c18955722e9a936c33ccd to your computer and use it in GitHub Desktop.
node parseData issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smith@manta # cat dataObj.json | ./demo.js | |
#!/usr/bin/env node | |
var config = require(__dirname + '/config.js'); | |
var r = require('rethinkdb') | |
var stdin = process.stdin, | |
stdout = process.stdout, | |
inputChunks = []; | |
stdin.resume(); | |
stdin.setEncoding('utf8'); | |
stdin.on('data', function (chunk) { | |
inputChunks.push(chunk); | |
}); | |
stdin.on('end', function () { | |
var inputJSON = inputChunks.join(""), | |
parsedData = JSON.parse(inputJSON) | |
r.connect(config.rethinkdb).then(function(connection) { | |
r.table('manta_logs') | |
.insert(parsedData) | |
.run(connection, function (err, result) { | |
console.log(result); | |
connection.close(function(err) { if (err) throw err; }); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment