Q:
How to run an external script (bash) from within a React app (node.js)
I am trying to run an external script (written in bash) from within a react app (node.js) to get different data.
The file structure looks like this:
/app/
/components/
/test/
/index.js
/index.jsx
I want to make a request to test.js inside the app/test/index.jsx component, then fetch data in test.js from an API in test.js and print the data in index.js.
I have tried this:
import test from './test/index';
test.request({
url: '',
}, (err, resp, body) => {
if (err) {
console.log(err);
} else {
console.log(body);
}
});
I get the following error:
The argument provided (-c option) could not be parsed. Usage: -c .
I know I could access the component from index.js but that does not seem to work either. I have tried various methods to get around the error and have gotten nowhere. I'm a bit out of my depth here.
index.js
import { test } from './test/index';
test.js
const request = require('request');
module.exports = {
request: function request(url, options, callback) {
options = options || {};
callback = callback || function(err, resp, body) {
if (err) {
console.log('Error:', err);
return;
}
Related links:
Comments