node.js 'Express' 不是识别命令(windows)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13553404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Express' is not recognized command (windows)
提问by pewpewlasers
Okay I am running node on windows (7). Using npm I just installed modules to d:\ directory. Therefore my files structure looks like the following:
好的,我在 Windows (7) 上运行节点。使用 npm 我刚刚将模块安装到 d:\ 目录。因此,我的文件结构如下所示:
D:\
-myproject
-node_modules
-.bin
-express
However, when I am in this 'myproject' directory, I can't seem to run 'express' for example:
但是,当我在这个“myproject”目录中时,我似乎无法运行“express”,例如:
D:\myproject\express site
'express' is not recognized as an internal or external command, operable program or batch file.
Am I doing anything wrong?
我做错了什么吗?
采纳答案by Hector Correa
My guess is that you didn't install Express globally. You can install express globally (and therefore available in your PATH) with the following command (see http://expressjs.com/guide.html) :
我的猜测是您没有全局安装 Express。您可以使用以下命令(请参阅http://expressjs.com/guide.html)全局安装 express(因此可以在您的 PATH 中使用):
npm install -g express
The way you install it is available only in the folder that you installed it and there is nothing wrong with that approach. There is very little advantage of having it available globally.
您安装它的方式仅在您安装它的文件夹中可用,并且该方法没有任何问题。在全球范围内使用它几乎没有什么优势。
If express is not in your PATH you can run it by entering the full path to it:
如果 express 不在您的 PATH 中,您可以通过输入它的完整路径来运行它:
\myproject\node_modules\.bin\express.cmd
回答by Mladen Rakonjac
Try:
尝试:
npm install -g express-generator@3
That solved problem for me.
那为我解决了问题。
Edit: for version 4
编辑:对于版本 4
npm install express-generator -g
Description: express is the package for dependency of express js. express-generator is the package for enabeling express command and create a sample project, etc. Assuming that this is kept separate for the decoupling of project dependency with cli tool of express.
说明:express 是 express js 的依赖包。express-generator 是用于启用 express 命令和创建示例项目等的包。假设将其与 express 的 cli 工具的项目依赖解耦是分开的。
Another SO ref: https://stackoverflow.com/a/41311733/1666582
另一个 SO 参考:https: //stackoverflow.com/a/41311733/1666582
回答by Danny Pule
Here's what to type in the command line to make it work in windows:
以下是在命令行中输入的内容以使其在 Windows 中工作:
npm install express-generator -g
回答by Maniac One
With the release of Express 4.0.0 it looks like you need to do
随着 Express 4.0.0 的发布,您似乎需要做
npm install -g express-generator.
回答by Yosi PW
We need to set path for express global directory
我们需要为 express 全局目录设置路径
C:\Users[User_Name]\AppData\Roaming\npm\
C:\用户[用户名]\AppData\Roaming\npm\
After add a new path, please reopen the CMD console
添加新路径后,请重新打开CMD控制台
回答by Lekan Stephen
Tried all of these and never worked. A repair of Node.js by kicking of installation and selecting repair option does the magic.
尝试了所有这些,但从未奏效。通过启动安装并选择修复选项来修复 Node.js 就很神奇。
Cheers
干杯
回答by Mo D Genesis
What worked for me was:
对我有用的是:
I used the windows command prompt instead of the node.js command prompt.
我使用了 windows 命令提示符而不是 node.js 命令提示符。
In windows 10 simply type in the windows search bar for "node"
在 Windows 10 中,只需在 Windows 搜索栏中键入“节点”
You see a node.js desktop app and a node js command prompt.
您会看到一个 node.js 桌面应用程序和一个 node js 命令提示符。
Choose the "node js command prompt"
选择“节点js命令提示符”
Type in the command prompt
在命令提示符中键入
npm install express-generator -g
Then navigate somewhere and type in:
然后导航到某个地方并输入:
express your-website-text-here -e
A directory with express files will be generated. Also now you won't see the express error.
将生成一个包含 express 文件的目录。此外,现在您将看不到快速错误。
回答by Piyush Bansal
I was able to fix with the following package install:
我能够通过以下软件包安装进行修复:
npm install express-generator -g
Thanks
谢谢
回答by Miguel Veces
I was able to fix this with:
我能够解决这个问题:
npm install express-generator -g
回答by Jaison
I have tried out all above solutions, but its did't worked for me, finally I have re-installed the node.jswith newer version and started to express install process again. Its worked for me.
我已经尝试了上述所有解决方案,但它对我不起作用,最后我重新安装了较新版本的node.js并再次开始表达安装过程。它对我有用。
npm install -g express
npm install -g express-generator

