Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

I've created a cli to format my project and install some dependencies.

I try to run

const runNpm = () => {

  return new Promise(resolve => {

    npm.load(function(err) {

      // handle errors

      npm.commands.install(

        ["@angular/core", "@angular/cli --save-dev"],

        function(err, data) {

          if (err) {

            reject(err);

          }

          console.log("dependencies installed");

          resolve();

        }

      );

      npm.on("log", function(message) {

        console.log(message);

      });

    });

  });

};

Without --save-dev it work perfectly

I've searched on internet, but couldn't find nothing.

1 Answer

0 votes
by (25.1k points)

For general npm packages installation using npm package manager from javascript code, or you can use this code

var npm = require('npm');

npm.load(function(err) {

  // install module ffi

  npm.commands.install(['ffi'], function(er, data) {

  });

  npm.on('log', function(message) {

    console.log(message);

  });

});

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...