I have a experiment code like this just to test calling a child process from NativeScript app (myapp/app/views/login/login.js):
var exec = require('child_process').exec;
exec('ls', function (error, stdout, stderr) {
if(stdout){
console.log('stdout: ' + stdout);
}
if(stderr){
console.log('stderr: ' + stderr);
}
if (error !== null) {
console.log('Exec error: ' + error);
}
});
when I test this app with "tns run ios --emulator", it gives an error like this:
file:///app/views/login/login.js:1:89: JS ERROR Error: Could not find module 'child_process'. Computed path '/Volumes/xxxx/Users/xxxx/Library/Developer/CoreSimulator/Devices/392A8058-694B-4A5D-B194-DF935815ED21/data/Containers/Bundle/Application/2822CD65-4E4D-443C-8272-135DB09353FC/sampleGroceries.app/app/tns_modules/child_process'.
My question is: how can I resolve this? Should I do "npm install child_process" on the app's directory? But while I was searching for solutions on Google, I read that it should be naturally included from node_modules...
I find a child_process module in: /usr/local/lib/node_modules/nativescript/lib/common
but as the error message says, it isn't included when I execute the app with tns command. Could someone tell me what I'm missing?
version info: npm: 3.10.10 node: 7.2.1 tns: 2.4.2