Skip to content

Instantly share code, notes, and snippets.

@Smithx10
Last active August 14, 2017 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Smithx10/f7d54c02760c18955722e9a936c33ccd to your computer and use it in GitHub Desktop.
Save Smithx10/f7d54c02760c18955722e9a936c33ccd to your computer and use it in GitHub Desktop.
node parseData issue
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