安装用于Node.js的Web服务器 [英] Installing a Web Server for Node.js

查看:131
本文介绍了安装用于Node.js的Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想随书​​我买了所谓的临角JS,和我有麻烦的Web服务器指向正确的端口。所以,我去命令行,运行节点,第一个错误我得到的是这样的,要安装连接时:

I'm trying to follow a book I purchased called "Pro Angular JS", and I am having trouble getting a web server pointed to the right port. So I go to the command line, run Node, and the first error I get is this, when trying to install connect:

npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)

好吧,很公平。所以我做的命令指定的,我把它安装只是作为用户,它结束了在我的用户根目录文件夹添加一个文件夹,名为node_modules。好吧,好像一切仍然是有意义的。

Ok, fair enough. So I do as the command specifies, and I get it to install just as the user, and it ends up adding a folder called node_modules in my user root folder. Ok, seems like everything still makes sense.

现在,这本书告诉我创造了Node.js的安装文件夹内的文件server.js。还有我的用户实际上没有创建Node.js的安装文件夹。我看到node_modules文件夹是肯定的。所以,我猜我的用户的根目录是安装Node.js的,但也许它隐藏的东西?我相信,当我使用节点Mac安装程序,它说,这是在USR / local / bin目录中创建。但是,我不知道如果这是我的我的计算机上的用户,甚至更多的root访问权限,以我的电脑。

Now, the book tells me to create a server.js file within the Node.js installation folder. There is no Node.js installation folder actually created on my user. I see the node_modules folder for sure. So I'm guessing the root directory of my user is where node.js was installed but maybe it's hidden or something? I believe when I used the Mac installer for Node, it said it was created at usr/local/bin. But I have no idea if that is my user on my computer, or even more root access to my computer.

最后,回到这个server.js文件...所以我用文本编辑器创建它,包含此code:

Lastly, back to this server.js file...so I created it with a text editor, containing this code:

var connect = require('connect');

connect.createServer(
connect.static(".../angularjs")

).listen(5000);

当然,他们要我这个文件添加到安装我节点的目录。目前,它的坐在那里我目前的用户(用户kst001)根目录。这也是当我使用NPM安装在外壳连接线安装了它我node_module文件夹的创建。他们还希望我能创建一个名为angularjs,在那里我将存储我的应用程序文件夹,并表示将其放置在安装node.js的根目录下。再次,坐在在根目录下有一切。然而,当我尝试和火起来的端口号为5000(本地主机:5000 / test.html的)我的测试文件,我得到一个找不到网页的错误。

And of course they want me to add this file to the directory where my Node is installed. Currently, it's sitting where my current user (user is kst001) root directory is. This is also where my node_module folder was created when I installed it using the npm install connect line in the shell. They also wanted me to create a folder called angularjs, where I would store my app, and said to place it in the root directory where node.js was installed. Once again, sitting in the root directory with everything else. Yet, when I try and fire up my test document in port 5000 (localhost:5000/test.html), I get a "could not find page" error.

已经在使用这个链接来解决我的问题,这似乎死在我的问题试过了,但它解决了什么:

Already tried using this link to solve my problem, which seems dead on for my issue, but it resolved nothing:

<一个href=\"http://stackoverflow.com/questions/23978734/node-connect-issue-object-function-createserver-has-no-method-static\">Node /连接问题目标函数createServer没有方法静态

我使用的是Mac,顺便说一句。任何想法,伙计们?任何帮助将是非常美联社preciated。

I'm using a Mac, by the way. Any ideas, guys? Any help would be much appreciated.

推荐答案

之所以 connect.static()不工作是,连接最新的主要版本( 3.X)不再包含所有连接在2.X捆绑的中间件。

The reason why connect.static() does not work is that the latest major version of connect (3.x) no longer contains all of the middleware that connect was bundled with in 2.x.

有关连接自述有,告诉你该模块的名称中间件引用的名单在故宫,让你对每个中间件旧的功能(如静态是现在分成了自己的模块的 服务静态 )。

The readme for connect has a list of middleware references that show you the name of the module on npm that gives you the old functionality for each middleware (e.g. static is now broken out into its own module serve-static).

这篇关于安装用于Node.js的Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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