How can I use NPM commands inside Node.js code?

Viewed 32

I have couple of questions:

  1. Didn't find any library that will allow me to use NPM commands (for example, install command), in Node.js code, without using exec shell commands, is there any library as described?

  2. Trying to find a way to get NPM response in JSON format. When using --json flag sometimes (especially when errors occurred) the response is not fully JSON.

    Example:

     npm install axdsadsadsadsa --json
     npm ERR! code E404
     npm ERR! 404 Not Found - GET https://registry.npmjs.org/axdsadsadsadsa - Not found
     npm ERR! 404
     npm ERR! 404  'axdsadsadsadsa@*' is not in this registry.
     npm ERR! 404
     npm ERR! 404 Note that you can also install from a
     npm ERR! 404 tarball, folder, http url, or git url.
     {
       "error": {
         "code": "E404",
         "summary": "Not Found - GET https://registry.npmjs.org/axdsadsadsadsa - Not found",
         "detail": "\n 'axdsadsadsadsa@*' is not in this registry.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
       }
     }
    
0 Answers
Related