r2DoesInc
r2DoesInc

Reputation: 3771

Node dependencies not found when ran programatically

UPDATE: There seems to be an issue with the cylon.js library. https://github.com/hybridgroup/cylon/issues/277

I am working on my first Node project and have run into some small issues with dependencies.

If I execute my server.js using node server.js, everything works as expected, all my deps are in the correct place and read just fine.

However, if I attempt to use init.d scripts to call it, or attempt to call it from within a different node program, I get errors that some of my dependencies are not found. It suggests using npm to reinstall them, and I have added the npm install line to the script just to make sure, but that has not had any effect.

I, [2015-06-29T17:29:12.661Z] INFO -- : [ardrobot] - Initializing connections.

Cannot find the 'cylon-intel-iot' module. This problem might be fixed by installing it with 'npm install cylon-intel-iot' and trying again.

    'use strict';

    var wait = require('wait.for')
    var Cylon = require('cylon');
    var bleno = require('bleno');
    var ip = require('ip');

    require('wait.for/parallel-tests.js')

    Cylon.robot({
      name: 'ardrobot',

      connections: {
        edison: { adaptor: 'intel-iot' }
      },
      devices: {
        turnServo: { driver: 'servo', pin: 3, },
        driveServo: { driver: 'servo', pin: 5, }
      },

      //These correspond to the actual api endpoints
      commands: function() {
        return {
          //servo
          set_angle: this.setAngle,
          set_drive_speed: this.setSpeed,
          do_arm: this.arm
        };
      },

      setAngle: function(val) {
        if (val != null) {
          this.turnServo.angle(this.turnServo.safeAngle(+val));
        }
      },
      setSpeed: function(val) {
        if (val != null) {
          this.driveServo.angle(this.driveServo.safeAngle(+val));
        }
      },

      arm: function() {
        var my = this;

        function arm1(param, callback){
          console.log('Arming sequence 1');
          my.setSpeed(180);
          wait.miliseconds(5000);
        };

        function arm2(param, callback){
          console.log('Arming sequence 2');
          my.setSpeed(0);
          wait.miliseconds(5000);
        };
        function arm3(param, callback){
          console.log('Arming sequence 3');
          my.setSpeed(90);
        };
        function prepareArm(){
          console.log('Beginning arming sequence');
          wait.for(arm1);
          wait.for(arm2);
          wait.for(arm3);
          console.log('Finished arming sequence');
        };

        wait.launchFiber(prepareArm);
      },
      work: function(my) {
      }
    }).start();

  Cylon.api(
      'http',{
      host: ip.address(),
      ssl: false,
      port: '3000'
    });

Upvotes: 0

Views: 109

Answers (1)

Patosai
Patosai

Reputation: 760

Try setting the NODE_PATH variable when you launch server.js.

The docs.

Upvotes: 0

Related Questions