0 votes
1 view
in Web Technology by (11.2k 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 (22.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);

  });

});

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...