user1770697
user1770697

Reputation: 11

Writing output of terminal to a RethinkDB database using Nodejs

I currently have a basic website/web-server setup through Node.JS (source available at github). I have a rethinkDB database running and that's all configured correctly.My main problem is figuring out how to write the output of terminal to RethinkDB. I figured the best way would be to echo the terminal output through a Cron job to a file. The main problem is how would I be able to load this file repetitively into the RethinkDB database to then display on the website?

Upvotes: 1

Views: 84

Answers (3)

AndersW
AndersW

Reputation: 48

In Node, you can very easily be notified of file changes through a callback. It is part of the Filesystem module and the function is fs.watchFile(filename[, options], listener)

Using that, you could maybe watch for changes and update the database as new data gets written.

fs.watchFile('message.text', function (curr, prev) {
  // Update db here
});

Upvotes: 0

neumino
neumino

Reputation: 4353

If you have one document per line on stdin, you can just pipe process.stdin to a transform stream that would call JSON.parse and then you can pipe it to a table using rethinkdbdash.

Upvotes: 1

janih
janih

Reputation: 2234

You can import JSON/CSV data from the command line, so you could include this import command in your cron job. More elegant way would probably be to use the External API access(if you are able to serve the terminal output via http).

Upvotes: 0

Related Questions