Thanks in advance for looking at my post!
提前感谢您查看我的帖子!
Main Questions:
-
What do I have to do to get http-server found when I call it from the command line?
当我从命令行调用http-server时,我该怎么办?
-
I feel this issue has revealed my linux incompetence. If I wanted to start from scratch with node and home brew, what files and directories would I have to remove (or make sure they have been removed by an uninstall command) before proceeding?
我觉得这个问题暴露了我的linux无能。如果我想从头开始使用node和home brew,在继续之前我必须删除哪些文件和目录(或确保它们已被卸载命令删除)?
Thanks in advance!
提前致谢!
Background
After I thought I fixed home brew (OS X 10.10 uses a newer version of Ruby), I tried reinstalling http-server with npm after I got the message -bash: http-server: command not found
. So I ran sudo npm install -g http-server
. Then I get a screen with lines that contain npm http GET https://registry/npmjs.org/
and npm http 304 https://registry/npmjs.org/
. The latter are followed by ~.node/bin/http-server -> ~.node/lib/node_modules/http-server/bin/http-server' and 'http-server@0.7.3 ~.node/lib/node_modules/http-server
.
在我认为我修复了home brew(OS X 10.10使用更新版本的Ruby)之后,我尝试在找到消息-bash:http-server:command之后用npm重新安装http-server。所以我运行了sudo npm install -g http-server。然后我得到一个屏幕,其中的行包含npm http GET https://registry/npmjs.org/和npm http 304 https://registry/npmjs.org/。后面跟着〜.node / bin / http-server - >〜.node / lib / node_modules / http-server / bin / http-server'和'http -server@0.7.3~.node / lib / node_modules / HTTP服务器。
Notes
-
I found this
/usr/local/bin/http-server@
, which I believe is the symbolic link for http-server.我找到了这个/ usr / local / bin / http-server @,我认为它是http-server的符号链接。
-
It appears that the link
http-server -> ../lib/node_modules/http-server/bin/http-server
does not exist, and I can't figure out why.似乎链接http-server - > ../lib/node_modules/http-server/bin/http-server不存在,我无法弄清楚原因。
-
The folder
/usr/local/lib/node_modules/http-server
does have0.6.1
and0.7.3
文件夹/ usr / local / lib / node_modules / http-server确实有0.6.1和0.7.3
-
The directory
0.7.3
just has a package directory followed by a package.json file. I'm confused as I would have expected this to contain more than just a package.json.目录0.7.3只有一个包目录,后跟一个package.json文件。我很困惑,因为我希望这包含的不仅仅是package.json。
-
I believe brew is installed correctly because
which brew
gives/usr/local/bin/brew
我相信brew安装正确,因为brew提供了/ usr / local / bin / brew
-
Also, I get
brew -v Homebrew 0.9.5
另外,我得到了酿造-v Homebrew 0.9.5
-
which npm
gives/usr/local/bin/npm
(This is also the same for node)其中npm给出/ usr / local / bin / npm(节点也是如此)
-
npm -v
gives1.4.28
npm -vgives 1.4.28
-
My Path variable is listed as in item 10 (broken out so it's more readable), below.
My Path变量列在第10项中(分解为更具可读性),如下所示。
-
- $HOME/.npm (I manually put this here, see 11 below for why)
- /bin
- /sbin
- /usr/bin
- /usr/sbin
- /usr/local/bin
- /usr/local/mysql/bin
- /opt/X11/bin
$ HOME / .npm(我手动把它放在这里,见下面的11为什么)
-
It appears that $Home/.npm has a list of packages that I've installed with npm. I thought that if I put $Home/.npm it may see http-server, which is in this directory. But it appears to be in the same structure as noted in point #4, above.
似乎$ Home / .npm有一个我用npm安装的软件包列表。我想如果我把$ Home / .npm放在它可能会看到http-server,它就在这个目录中。但它似乎与上面第4点所述的结构相同。
-
I'm using OS X 10.10
我正在使用OS X 10.10
-
Yesterday I installed X Code 6.1 because apparently it was required due to a command line issue.
昨天我安装了X Code 6.1,因为由于命令行问题显然需要它。
$ HOME / .npm(我手动把它放在这里,见下面的11为什么)/ bin / sbin / usr / bin / usr / sbin / usr / local / bin / usr / local / mysql / bin / opt / X11 / bin
1 个解决方案
#1
1
Global installation
Did you install http-server
with npm globally?
你是否全局安装了带有npm的http-server?
To install a module globally (which you need for a CLI), you must enable the global flag:
要全局安装模块(CLI需要),必须启用全局标志:
npm install -g http-server
npm install -g http-server
npm scripts
It is also possible to install CLI modules locally, and run them from npm scripts.
也可以在本地安装CLI模块,并从npm脚本运行它们。
In your package.json
:
在你的package.json中:
...
devDependencies: {
"http-server": "^0.8.5"
},
scripts: {
"serve": "http-server ./public"
}
...
then
http-server ./public
# unsuccessful
npm run serve
# successful
#1
1
Global installation
Did you install http-server
with npm globally?
你是否全局安装了带有npm的http-server?
To install a module globally (which you need for a CLI), you must enable the global flag:
要全局安装模块(CLI需要),必须启用全局标志:
npm install -g http-server
npm install -g http-server
npm scripts
It is also possible to install CLI modules locally, and run them from npm scripts.
也可以在本地安装CLI模块,并从npm脚本运行它们。
In your package.json
:
在你的package.json中:
...
devDependencies: {
"http-server": "^0.8.5"
},
scripts: {
"serve": "http-server ./public"
}
...
then
http-server ./public
# unsuccessful
npm run serve
# successful