I run the test.js file
import { exec, spawn , fork } from 'child_process'; const ls = spawn(`/data/files/test.js` , [] , { detached : true, shell : true }); ls.stdout.on('data', (data) => { console.log(`stdout: ${data.toString()}`); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data.toString()}`); }); ls.on('exit', (code) => { console.log(`child process exited with code ${code.toString()}`); }); But errors are displayed.
> /data/files/test.js: 2: /data/files/test.js: let: not found > /data/files/test.js: 3: /data/files/test.js: Syntax error: "(" > unexpected Contents of the test.js file
let logStr = ""; var fs = require("fs");
commandspecify the path to the node, inargspath to the executable file - andreymal#!/usr/bin/env nodein the first line of the file and make the file executable - nörbörnën