Once you've installed NodeJS, you'll have a executable in your computer named NodeJS which is a shell. I was wondering what can I do with that... here you're able to run JS code as, for example, in the browser's console, great.
Now, is it possible to require modules in that env? Doing so, I'd be able to run some JS code using functions provided by those modules which IMO would be really, really great.
I've tried installing the modules with the -g
option (for example npm install -g express
); then (in that shell) I want to run require('express')
but it doesen't work, it says:
Error: Cannot find module 'express'
at Function.Module._resolveFileName ...
Ideas?
As per issue #5431, looks like the Node.JS REPL doesn't find globally-installed modules and this is expected behaviour.
In the article linked from that issue, it reads:
This is your case, sou need to install
express
locally:Note that you get
undefined
as a result because of thevar
statement, but it did work.