Sorry, but you make me confounded. In this case, I can’t call that python script from my client code !
How can I call a python script in server side and get the result then ?
No - but you can call a server method from your client and get the result back to your client.
Check this quick repo I put together - it runs an ls /tmp
command (but you can run python just as well) and shows the list in the browser.
Thank you so much I hope that helps me ^^
Incidentally, if you’re not interested in stderr
, you can write the server/main.js
in even fewer lines of code:
import { Meteor } from 'meteor/meteor';
const child_process = require('child_process');
Meteor.methods({
lstmp() {
const syncExec = Meteor.wrapAsync(child_process.exec, child_process);
return syncExec('ls -l /tmp');
},
});
and you don’t need to do meteor npm i fibers --save
There is something I can’t understand it ! Why when I copied the contents of your main.js file to my file (server/main.js also), my application crached ! and in the console dispaly to me ReferenceError: require is not defined in line
const child_process = require(‘child_process’);
and SyntaxError: Unexpected reserved word in this line:
import { Meteor } from ‘meteor/meteor’;
I know I ask much but that’s important to me…
It sounds like you don’t have the ecmascript
package added. Try
meteor add ecmascript
Instead of copying files, you could just clone the repo and then:
meteor npm i
meteor
I cloned your project and it’s working well and thank you, but I want this functionality works in my own project (for that I copied your main.js contents to mine main.js). About ecmascript now, it was added from the beginning of my project and I have 0.4.6_1 version ! It can be other raison than ecmascript ?
Well, require
requires the modules
package - but that should be pulled in by ecmascript
.
Can you share the contents of your .meteor/packages
and .meteor/versions
files?
Yes of course… package.json & version
I tried meteor add ecmascript now and I got :
If you notice problems related to these missing modules, consider running:
meteor npm install --save jquery spin.js d3 datatables.net datatables.net-bs
datatables.net-buttons datatables.net-responsive desandro-get-style-property
eventie doc-ready desandro-matches-selector wolfy87-eventemitter get-size
fizzy-ui-utils outlayer switchery
Despite the package ecmascript added and the proof I have ecmascript@0.4.6_1 in my package.json file.
So I have to add all this packages ?
I have no idea where they have come from - not from meteor add ecmascript
! It looks like you have some dependency in your project.
Looking at your package.json
you have some npm dependencies which I don’t believe you need (childish-process
and childprocess
). I would start by removing these. If you look at my working package.json
I only have fibers
and meteor-node-stubs
.
Yes I don’t need them(childish-process and childprocess) anymore I added them when I was teasting some examples.
About the files, you take a look ? Everything is okay normally, no ?
I have to add meteorhacks:npm package: meteor add meteorhacks:npm
Now const child_process = require(‘child_process’); works for me without error
Edit: I am wrong, this package works only in 1.2 version
Do you have a repo I can look at? I think we’re going round in circles at the moment.
Sorry it’s a confidential project
You absolutely do not need this package.
I’m not sure how we can move this forward. My feeling is that you have tried a number of approaches without success and have left your project in a broken state. Can you revert to an earlier branch or commit before you made the original post?
Yes, I have a version.
I would restore that version, then:
-
Clean up your
node_modules
withmeteor npm prune
. -
Check you have
ecmascript
added (and if not:meteor add ecmascript
). -
Check your project’s
.meteor/packages
file and ensure that your changes are correct. -
Add in the simplest server-side method to test:
import { Meteor } from 'meteor/meteor';
const child_process = require('child_process');
Meteor.methods({
lstmp() {
const syncExec = Meteor.wrapAsync(child_process.exec, child_process);
return syncExec('ls -l /tmp');
},
});
- Use a simple client-side template to make the call (consider copying the working example I posted).
When I add the ecmascript package, I got this in my terminal, just when I run my app :
If you notice problems related to these missing modules, consider running:
meteor npm install --save jquery spin.js d3 datatables.net datatables.net-bs
datatables.net-buttons datatables.net-responsive moment
desandro-get-style-property eventie doc-ready desandro-matches-selector
wolfy87-eventemitter get-size fizzy-ui-utils outlayer switchery
=> Started your app.
=> App running at: http://localhost:3000/
What I have to do ?
And what do you get if you run the app without adding ecmascript (you’ll need to revert again)?