4

I just get started on nodejs. I have installed nodejs and npm. Now, I want to install some packages like mongodb and express. As my default directory path in cmd is C:\>Users\administrator, do I need to make current folder as nodejs folder to run npm install express/coffee-script or I can just run this command under the default directory path mentioned above?

By the way, I always see the npm install command provided by others starts with a dollar sign, but I can only use the command without the dollar sign. So what does the dollar sign stand for?

1 Answer 1

7

By default, npm will run in local mode, and install scripts into ./node_modules. This is great if you need to require your scripts, as you'll do with Express.

Calling it with the -g option installs it globally, wherever node is installed (usually, on Linux, in /usr/local. This is great for packages that are meant to be run using the shell (for example, Supervisor).

Generally, if you want to develop a node.js application under C:\foo\bar\myapp, you will run npm from there.

FYI, the $ sign is a general indication meaning that the following command is meant to be run on the command line.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot for your information. But I'm still a little bit confused. As I used the nodejs installer which has npm included it, I noticed that there is already a directory path under the nodejs folder which is node_modules\npm\node_modules. And there are already several modules under this path. So what I'm thinking is if I need another folder under the default folder provided by cmd to store some other modules. I should install all my modules in nodejs\node_modules\npm\mode_modules, right?
No. Node.JS directory has a node_module directory, which contains system-wide modules (installed with the -g switch). NPM is one of them. node_modules\npm\node_modules contains NPM dependencies. If you want to create your Node.JS app in the folder myapp, just go there with cd myapp, and run NPM from there. It can't be easier. Really.
So what you mean is it makes no sense to just install a package like express under the default path provided by cmd. I should install packages based on my applications. If I have several apps which all require express module, I should install this module for them respectively, right?
You're all right. As I said, installing apps under the global path generally only makes sense for packages meant to be used with the command line. You won't even be able to require() packages installed globally without additional steps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.