How to require an npm module installed via installer?


#1

Hi,

So I managed to install an npm package, as a dependency for a plugin, via installer, and it seems to have been installed correctly (under c9sdk/node_modules, in my case), but requiring it from my plugin fails with a 404. Anything I’m missing?

/* install.js */
define(function(require, exports, module) {

module.exports = function(session, options){
    session.install({"npm": "cloudrail-si"});
    session.start();
};

// version of the installer. Increase this when installer changes and must run again
module.exports.version = 1; 

});
/* plugin.js */
define(function(require, exports, module) {
    // ...
    function main(options, imports, register) {
        var cloudrail = require("cloudrail-si");
        // ...    

#2

plugin.js can’t require modules installed with installer because it runs in the browser, what are you trying to do?
Most likely you need to create script, and use vfs.spawn to run it.


#3

Oh, I know it runs in the browser, but still thought it would be possible a la https://github.com/c9/core/blob/master/plugins/c9.ide.ace/ace.js#L40!

Goal is to simply use the capabilities of cloudrail-si to add file-syncing features. Should that rather be implemented as a remote plugin?


#4

PS, is vfs.spawn documented somewhere?


#5

Remote plugin will work too, that mostly depends on how cpu intensive is the task you want to run, and weather stopping it when user disconnects is ok.

in the simplest case, when keeping process after user disconnect is not important, proc.spawn can be used as

var proc = imports.proc
proc.spawn("bash", { args: ["-x"] }, function(err, process) {
    if (err) console.log(err)

    process.stdout.on("data", function(e) { console.log(e + "") })
    process.stderr.on("data", function(e) { console.log(e) })

    process.stdin.write("ls -la \n")
})