Reputation: 606
I am working on a log tail project using node.js but the function process.createChildProcess
is not working.Is there any alternative to that?
var sys = require('sys');
var filename = "test.txt";
var process=require('process')
if (!filename)
return sys.puts("Usage: node watcher.js filename");
// Look at http://nodejs.org/api.html#_child_processes for detail.
var tail = process.createChildProcess("tail", ["-f", filename]);
sys.puts("start tailing");
tail.addListener("output", function (data) {
sys.puts(data);
});
// From nodejs.org/jsconf.pdf slide 56
var http = require("http");
http.createServer(function(req,res){
res.sendHeader(200,{"Content-Type": "text/plain"});
tail.addListener("output", function (data) {
res.sendBody(data);
});
}).listen(8000);
Here I am getting error:
var tail = process.createChildProcess("tail", ["-f", filename]);
^
TypeError: process.createChildProcess is not a function
Any help will be appreciated
Article referred: https://thoughtbot.com/blog/real-time-online-activity-monitor-example-with-node-js-and-websocket
Upvotes: 0
Views: 233
Reputation: 11
You can use spawn
for creating a child process in Node.JS.
Here's an example based on your code:
const { spawn } = require('child_process');
/* Some Code Here! */
var tail = spawn("tail", ["-f", filename]);
Upvotes: 1