Need help understanding requiring modules.

64 views
Skip to first unread message

Michael Deremer

unread,
May 13, 2015, 1:55:57 PM5/13/15
to nod...@googlegroups.com
I have nodejs installed on a debian distro on my raspberry pi. I have installed nodejs and npm successfully. 

I wanted to install the pi-gpio module so i could nodejs to access my gpio pins.

I'm using the root user to cancel out permissions errors. I realize thats unsafe and i have a user setup using the quick2wire-gpio-admin utility.

I navigate to my project folder: /usr/michael/
the director listing looks like:
controller.js   - this is my program. It starts a webserver and attempts to do var gpio = require('pi-gpio') and then read a gpio pin.

While in my /usr/michael director i did an npm install pi-gpio.
The install was successful and it placed a node-module folder within my project folder.

documentation here: https://www.npmjs.com/package/pi-gpio specifies to include the module by using
var gpio = require("pi-gpio");

My absolute path for the pi-gpio module looks like:
/usr/michael/node-module/pi-gpio/pi-gpio.js

When i require the file as the example states i get an error saying it "cannot find module".
Do i need to modify the require path? Are my permissions screwed up.
I've tried:
 require('pi-gpio')
require('./node-module/pi-gpio')
require('./node-module/pi-gpio/pi-gpio.js')

Can someone explain what that require function is looking for?

var gpio = require("pi-gpio");
gpio.read(16, function(errvalue) {
    if(err) throw err;
    console.log(value); // The current state of the pin 
});

Michael Deremer

unread,
May 13, 2015, 7:59:01 PM5/13/15
to nod...@googlegroups.com
Found this:
http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm

I'll try it tonight, but i'm pretty sure i've already tried all this.

// ravi

unread,
May 13, 2015, 8:20:27 PM5/13/15
to nod...@googlegroups.com
On May 13, 2015, at 1:55 PM, Michael Deremer <michaeld...@gmail.com> wrote:
>
> I have nodejs installed on a debian distro on my raspberry pi. I have installed nodejs and npm successfully.
>
> I wanted to install the pi-gpio module so i could nodejs to access my gpio pins.
>
> I'm using the root user to cancel out permissions errors. I realize thats unsafe and i have a user setup using the quick2wire-gpio-admin utility.
>
> I navigate to my project folder: /usr/michael/
> the director listing looks like:
> controller.js - this is my program. It starts a webserver and attempts to do var gpio = require('pi-gpio') and then read a gpio pin.
>
> While in my /usr/michael director i did an npm install pi-gpio.
> The install was successful and it placed a node-module folder within my project folder.
>


Michael, do you mean “node_modules"?

—ravi


> documentation here: https://www.npmjs.com/package/pi-gpio specifies to include the module by using
> var gpio = require("pi-gpio");
>
> My absolute path for the pi-gpio module looks like:
> /usr/michael/node-module/pi-gpio/pi-gpio.js
>
> When i require the file as the example states i get an error saying it "cannot find module".
> Do i need to modify the require path? Are my permissions screwed up.
> I've tried:
> require('pi-gpio')
> require('./node-module/pi-gpio')
> require('./node-module/pi-gpio/pi-gpio.js')
>
> Can someone explain what that require function is looking for?
>
> var gpio = require("pi-gpio");
> gpio.read(16, function(err, value) {
> if(err) throw err;
> console.log(value); // The current state of the pin
> });
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/97706a8b-2347-4b09-86da-cee6b9e1db19%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

John Shaver

unread,
May 14, 2015, 11:27:11 AM5/14/15
to nod...@googlegroups.com

This all seems good... It should be able to find the module where it is.  What command are you using to run your script and where are you invoking it from?

-John

--
Reply all
Reply to author
Forward
0 new messages