Calling npx from a node.js file

Vasily

I've tried using exec with a bash file, I've tried using direct calls, I've tried digging into npm and npx docs but there seems to be no answer to this question: how can an npx call be triggered form node.js code?

An answer that triggers the same functionality as an npx call without actually being written as an npx call would also be acceptable.

kiriMCplay

I am not really sure where your problem is...

  • how you call npx scripts in general?
  • running shell commands from within node?
  • Running specifically npx commands? Is there an error you get?

The most widespread way to run shell commands would be child_process, and I don't know why you couldn't just put an npx command in there (I just tested it with npx --help and that worked):

const { exec } = require("child_process");

exec("echo Hello World", (err, stdout, stderr) => {
  if (err) {
    console.error();
    console.error("Error:");
    console.error(err);
    console.error();
  }
  console.log(stdout);
  console.error(stderr);
});

Now, this might be what you meant by "tried using exec", and you just get an error doing that. Of course, it would be helpful to have that error in that case, but maybe it is that npx isn't found.

Make sure you have npx installed then - maybe it's just npms virutal environment that can't access it, so you could use npm install npx to install it into there. If you are running it with npm, make sure it's installed globally: npm install -g npx.

If it is a different problem, please provide more information on what exactly you are lacking or potential errors you are getting.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a function from another JS file And Node Directory Structure

From Dev

calling callback from another file? node js express

From Dev

Batch File Calling Node.js - How to Set ERRORLEVEL From Node

From Dev

Calling stored procedure from node js

From Dev

Proper calling sequence to have Node.js disconnect from database after processing input file

From Dev

how to pass parameter from npx command to playright.config.js file

From Dev

Vue - calling REST API from js file

From Dev

Calling .js file from HTML using AJAX

From Dev

Calling method from compiled js file

From Dev

Calling Routes from a js angular 1.5.8 file

From Dev

Calling a function from a JS file not working

From Dev

Creating a function and calling it on another file in node.js

From Dev

calling two functions in a single file in node.js

From Dev

calling a function in another file in javascript using node.js

From Dev

Calling a Javascript function from an external js file in the html file

From Dev

Vue.js calling an async function from external js file

From Dev

Calling Function from another JS file(not a game state) Phaser js

From Dev

Calling a JS function from a JS-File in PHP

From Dev

Calling a Node.js module function from within the module

From Javascript

Calling JavaScript from C++ with node.js

From Java

Calling a node.js script from inside java

From Dev

Node.js calling function from other function not working

From Dev

Calling method in Node js from browser (Using Express)

From Dev

Node.js: Pass data from a callback to the calling function

From Dev

Calling Microsoft QnA maker API from Node.js

From Dev

Calling JS function multiple times from different node addon methods

From Dev

Calling Delphi stdcall function with pAnisChar from node js

From Dev

Calling a client side function from server side in node.js

From Dev

npx babel not reading configuration from babel.config.js

Related Related

  1. 1

    Calling a function from another JS file And Node Directory Structure

  2. 2

    calling callback from another file? node js express

  3. 3

    Batch File Calling Node.js - How to Set ERRORLEVEL From Node

  4. 4

    Calling stored procedure from node js

  5. 5

    Proper calling sequence to have Node.js disconnect from database after processing input file

  6. 6

    how to pass parameter from npx command to playright.config.js file

  7. 7

    Vue - calling REST API from js file

  8. 8

    Calling .js file from HTML using AJAX

  9. 9

    Calling method from compiled js file

  10. 10

    Calling Routes from a js angular 1.5.8 file

  11. 11

    Calling a function from a JS file not working

  12. 12

    Creating a function and calling it on another file in node.js

  13. 13

    calling two functions in a single file in node.js

  14. 14

    calling a function in another file in javascript using node.js

  15. 15

    Calling a Javascript function from an external js file in the html file

  16. 16

    Vue.js calling an async function from external js file

  17. 17

    Calling Function from another JS file(not a game state) Phaser js

  18. 18

    Calling a JS function from a JS-File in PHP

  19. 19

    Calling a Node.js module function from within the module

  20. 20

    Calling JavaScript from C++ with node.js

  21. 21

    Calling a node.js script from inside java

  22. 22

    Node.js calling function from other function not working

  23. 23

    Calling method in Node js from browser (Using Express)

  24. 24

    Node.js: Pass data from a callback to the calling function

  25. 25

    Calling Microsoft QnA maker API from Node.js

  26. 26

    Calling JS function multiple times from different node addon methods

  27. 27

    Calling Delphi stdcall function with pAnisChar from node js

  28. 28

    Calling a client side function from server side in node.js

  29. 29

    npx babel not reading configuration from babel.config.js

HotTag

Archive