在Windows 7中安装Express.JS的问题 [英] Issues with installing Express.JS in Windows 7

查看:120
本文介绍了在Windows 7中安装Express.JS的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过安装程序在他们的网页上安装了Node.js,并添加了我的环境变量的路径,所以我可以使用节点 npm 通过命令行。如果我做一个明确的应用程序,它的作品,但我必须手动创建。



这很好,我猜,但我想知道为什么我不能使用 express 命令?我正在获得

 `express`不被识别为内部或外部命令,可操作的程序或批处理文件。 

我注意到,express安装在C:\Username\\\
ode_modules中,而不是我以为会去,在C:\Program Files\Nodejs\\\
ode_modules。这是个问题吗?

解决方案

虽然这不一定是一个问题,但令人厌烦的是,即使您可以浏览它,错误也是一个错误。 / p>

尽管您可以引用其他节点模块,即使它们不在节点目录中,据我所知,节点要求模块位于节点_模块文件夹内的 Nodejs 目录中,以便自动找到它们。 (我在osx上有一个类似的问题,这个方法解决了它)。



尝试移动



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



另外



您还可以使用以下方式全局安装模块:

  npm install express -g 

它允许您访问它们,而不必担心您的节点目录,尽管这些更难以管理,您应该尽量避免,如果可以。



从节点博客中:


就像全局变量是粗体一样,但是在某些方面也是必需的
案例,全球包裹很重要,但最好避免,如果不是
需要。



一般来说,经验法则是:



如果您正在安装要在程序中使用的东西,
使用require('whatever'),然后在本地安装在
的根目录下。如果您要在
中安装您要使用的shell,在命令行或其他东西上安装,那么
它的二进制文件最终会在您的PATH环境变量中。


资源




  • a href =https://stackoverflow.com/questions/5817874/node-js-npm-is-not-installing-module-in-the-default-path>相关SO问题/答案

  • 节点博客


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 command line. If I make an express app, it works, but I have to create it manually.

This is fine I guess, but I was wondering why I can't use the express command? I am getting

`express` is not recognized as an internal or external command, operable program or batch file.

I noticed that express installs in C:\Username\node_modules instead of where I thought it would go, in C:\Program Files\Nodejs\node_modules. Is this a problem?

解决方案

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

这篇关于在Windows 7中安装Express.JS的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆