While Trying to use child Process to have a multiple ssh connection I got this erroryour text
`
inside process.on
node:internal/child_process:754
throw new ERR_MISSING_ARGS('message');
^
TypeError [ERR_MISSING_ARGS]: The "message" argument must be specified
at new NodeError (node:internal/errors:372:5)
at process.target._send (node:internal/child_process:754:13)
at process.target.send (node:internal/child_process:739:19)
at process.<anonymous> (C:\Users\dell\Desktop\Sublist3e\functions\subdomains.js:16:13)
`
I was trying to connect to ssh using child process.Let me know if this is possible and help me find the solution
process.on('message', (message) => {
let subfind = findSubs(message.URl);
console.log('inside process.on')
// send the results back to the parent process
process.send(subfind);
// kill the child process
process.exit();
})
function findSubs(URl) {
ssh
.connect({
host: '192.168.199.131',
username: 'aavash',
password: 'admin'
})
.then(() => {
return ssh.execCommand(`subfinder -d ${URl} -o /home/aavash/Desktop/${URl}.txt`)
.then((result) => {
console.log(result.stdout)
})
})
.then(() => {
// Local, Remote
return ssh.getFile(`C://Users/dell/Desktop/Sublist3e/Subdomains/${URl}.txt`, `/home/aavash/Desktop/${URl}.txt`).then(function (Contents) {
console.log("The File's contents were successfully downloaded")
})
})
.then(()=> {
fs.readFileSync(`C://Users/dell/Desktop/Sublist3e/Subdomains/${URl}.txt`, function (err, data) {
if (err) throw err;
subs = data.toString().split("\n");
console.log(subs)
for(i in subs) {
console.log(subs[i]);
}
})
})
}
I call the above file as shown below:
app.get('/test', (req, res) => {
URl='hackerrank.com'
const child = childProcess.fork('./functions/subdomains.js');
child.send(URl)
child.on('message', (message) => res.render('subdomains', { Domain: URl, subdomains: subs }) )
})
There might be multiple erros in the code
You are not returning anything from
findSubs
. Therefore the call tofindSubs
inlet subfind = findSubs(message.URl);
returns undefined which you are passing inprocess.send(subfind);
Return the contents of the file from the function
findSubs()
. Use async await for the ssh calls and the file reading in the functionfindSubs()
and return the contents of the file.also await
findSubs()
in the message event callback of the child process