small medium large xlarge

Back to: All Forums  CoffeeScript
04 May 2011, 06:40
Vladimir Kelman (15 posts)

I’m installing Node and CoffeeScript on LinuxMint 10 machine (working under VMware virtual machine). Totally new to Linux, unfortunately.

I successfully went through the steps of Chapter 1.1. “$ node -v”, “$ npm -v”, and “$ coffee -v” return meaningful values. Where I got an issue is with adding node_modules subdirectory to NODE_PATH.

”$ npm ls -g” on my machine returns “/home/vkelman/local/lib”. So I then typed the following: “$ export NODE_PATH=/home/vkelman/local/lib/node_modules”. Is it what I was supposed to do? (Again, I’m new to Linux.) Or should I run some command which included “~/.profile”? Anyway, “> require(‘coffee-script’)” returns “Error: Cannot find module ‘coffee-script’”.

What did I do wrong?

By the way, LinuxMint has some graphical windows-like system, including an analog of Windows Explorer. So I looked at “/home/vkelman/local/lib/node_modules” folder and it indeed includes “coffee-script” subfolder. It is here but I didn’t set NODE_PATH properly.

04 May 2011, 16:07
Chad Reynoldson (2 posts)

I had a similar situation with my mac (and I too am somewhat of a newbie to mac). I found the env command, which showed me that NODE_PATH was not getting set, even though I had added it to the .profile file as instructed. In my case, I’m using the zsh shell and I ended up editing the .zshrc file instead (vim /~.zshrc).

I’ve still not convinced myself that this is the best place to put it because if I use something other than zsh, it will fail again.

Hope this helps. I ended up learning a lot about the zsh shell, vim, and environment variables in my long search to make it work, so all is not a loss.

04 May 2011, 16:11
Leroy Campbell (3 posts)

You’ll want to add the line @export NODE_PATH=/home/vkelman/local/lib/node_modules@ to the file @~/.profile@. That way, you won’t need to set NODE_PATH every time you launch your terminal.

Afterwards, relaunch your terminal, then type @echo $NODE_PATH@ and you should see @/home/vkelman/local/lib/node_modules@. Now you should be able to require CoffeeScript in the Node REPL.

04 May 2011, 16:13
Steven Nunez (5 posts)

I used bash and added the export to the ~/.bashrc. Worked after that.

04 May 2011, 16:52
Trevor Burnham (53 posts)

@Vladimir It sounds like you did everything correctly… Did you run

export NODE_PATH=/home/vkelman/local/lib/node_module

and then immediately run node from the same window? (When you run that command, it only sets NODE_PATH for the current bash session. That’s why I say that you should add that line to your ~/.profile file, which bash reads every time it starts a new session.)

You can test whether NODE_PATH is set correctly by running

05 May 2011, 01:11
Vladimir Kelman (15 posts)

OK, I got it working.

You know, with my a near-to-zero knowledge of Linux (always wanted to learn it never had time) elementary things turn into issues. You wrote, “On my system, that means adding export NODE_PATH=/usr/local/lib/node_modules to ~/.profile.” For me it was a challenge to find ~/.profile file and to understand what program to use for its editing :(

Still, further chapters are going to be about CoffeeScript, not about Linux, so I should be able to study it :)

05 May 2011, 03:25
Trevor Burnham (53 posts)

Believe me, I’ve been there. I wish it weren’t necessary to mess with environmental variables in order to use Node/npm. Maybe some day… glad you got it working, though.

If you use Linux, you really should learn either vim or emacs; once you’ve done that, editing ~/.profile is as easy as typing vim ~/.profile or emacs ~/.profile. (I’m on a Mac using TextMate, so I type mate ~/.profile.)

03 Jun 2011, 15:59
Ronald H Bingham (2 posts)

I was delighted to purchase and read your well written CoffeeScript book

I’ve spent nearly a day trying to install node and npm to no avail. After installation everything appears ok.

~ ron$ node -v

However when I type echo $NODE_PATH, I get a blank line.

When I open a new terminal window, I get the following:

~ ron$ node -v
-bash: node: command not found
ron$ echo $NODE_PATH

Again a blank line for $NODE_PATH.

Here is my ~/.profile file

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
# Your previous /Users/ron/.profile file was backed up as /Users/ron/.profile.macports-saved_2009-09-19_at_09:53:45

# MacPorts Installer addition on 2009-09-19_at_09:53:45: adding an appropriate PATH variable for use with MacPorts.
# export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

export PATH="/usr/local/:$PATH"

export NODE_PATH="/usr/local/lib/node_modules"

BTW, I uninstalled macports in my all day effort.

04 Jun 2011, 00:48
Trevor Burnham (53 posts)

Hi Ronald,

Sorry for not replying sooner. What happens when you type @source ~/.profile@? Do you get an error? If not, can you successfully run @echo $NODE_PATH@ after that?

If that works around the problem, then the issue is that @~/.profile@ isn’t being loaded when you start your shell. I’ve seen this happen before, though the cause remains a mystery to me. I’d suggest adding the @PATH@ and @NODE_PATH@ lines to @~/.bash_profile@ instead and seeing if that works. (You are using the bash shell, right?)

05 Jun 2011, 05:01
Ronald H Bingham (2 posts)

Hi Trevor,

Thanks for the reply. Yep, you called it, ~/.profile isn’t being loaded. Before I got your reply I had stumbled across . ./.profile which does the same thing as source ~/.profile and I was off to the coffee shop! Yes I’m on a Mac using the bash shell.

I’m trying to understand the this/@ construct. How is this like or unlike ruby?

06 Jun 2011, 18:45
Trevor Burnham (53 posts)

Mm, I think the context section of the book explains @this/@@ pretty thoroughly (in the “Context” section), though if you’d still like to learn more, I’d refer you to JavaScript Garden:

I’d say the main difference vs. Ruby is that, thanks to the @call@ and @apply@ methods, @this@ can be literally anything each time a function is called.

28 Jun 2011, 23:37
Meng Fung (1 post)

Hi for Mac users who followed the node.js install using the installation guide found here:

Do this.

echo ‘export NODE_PATH=$HOME/local/node/lib/node_modules’ » ~/.profile source ~/.profile

This can also help ubuntu users by replacing ~/.profile with ~/.bashrc

31 Jul 2011, 10:50
David P. Gero (2 posts)

Linux users may need to use .profile to .bashrc file.

Important on Ubuntu: Also use sudo then you won’t have struggles with exporting path: curl | *sudo* sh instead of curl | sh

Enjoy Coffee:)

27 Jun 2012, 13:14
Migo Fast (1 post)

I do have coffee script installed I can see it in the directory when I type echo $NODE_PATH into the shell I get


but when I


I get

Error: Cannot find module 'coffee-script'

You must be logged in to comment