Issues with installing Express.JS in Windows 7

前端 未结 5 1065
北恋
北恋 2021-02-13 13:30

I have installed Node.js through the installer on their webpage and added it\'s path to my environment variable so I can use node and npm through the c

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 14:31

    Although this is not necessarily a problem, it's annoying and and error is an error even if you can navigate around it.

    Although you can reference other node modules even if they are not in the node directory, as far as I understand node requires the modules to be in the node_modules folder within the Nodejs directory in order to automatically find them. (I had a similar issue on osx and this method solved it.)

    Try moving the contents of

    C:\Username\node_modules into C:\Program Files\Nodejs\node_modules\

    Alternatively,

    You can also install modules globally with:

    npm install express -g
    

    which allows you to access them without having to worry about your node directory, although these are then more difficult to manage and "you should try to avoid if you can".

    From the Node Blog:

    Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.

    In general, the rule of thumb is:

    If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

    Resources

    • Related SO question/answers
    • The Node blog post

提交回复
热议问题