0

I'm trying to run a component.io method from inside a script, though this shouldn't be specific to component.io.

Under normal circumstances, in a terminal, I'd write. component install to install all the dependencies.

I've tried to different methods, but can't seem to get either to work (or show any output).

First I tried including component as a module

var componentIO = require('component');
componentIO.install();

Unfortunately, when I do this, nothing happens.

When I output console.log(componentIO), it outputs as part of the object install: [function], so I think I'm calling it correctly.

The other way I tried was via child_process

var cp = require('child_process');
var componentIO = cp.fork('component');
componentIO.send('install');

but again, I don't see any output in the terminal.

Am I taking the wrong tact to run commands from within node?

0

1 Answer 1

1

You can use component-installer module to install components.

var Installer  = require('component-installer');
var installer = new Installer(__dirname);

installer.on('package', function (pkg) {
  console.log('installing', pkg.name, pkg.version);
});

// arguments: (package name, package version)
installer.installPackage('matthewmueller/io', 'master');

console.log('Packaged installed.');
Sign up to request clarification or add additional context in comments.

2 Comments

Though this may be the correct answer with regards to component.io, I am actually trying to get something that works more generally.
@pedalpete The general way is to pass the full path of component to cp.fork(). You can run which component in the terminal to get the full path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.