I know that in Node.js, one could use execSync (such as this post: Saving the output of a child process in a variable in the parent in NodeJS). Could Express.js do the same? If not, is there a way for Express.js to execute Linux command line? Thanks!
Asked
Active
Viewed 145 times
1 Answers
1
Express.js is just a library that runs in the nodejs environment. So, when you're using Express.js, you're using it inside of the nodejs environment. So, EVERYTHING that is available in nodejs is available in an application using the Express.js library. So yes, of course, execSync()
can be used with Express.
Now, one would not normally use a synchronous function like that in a server implementation because that will block the entire server from serving any other requests during the duration of that call to execSync()
. You could instead use .exec()
or .execFile()
instead and code appropriately to use them as asynchronous operations.

jfriend00
- 683,504
- 96
- 985
- 979