如何使用Node.js运行用JS编写的服务器 [英] How to run server written in js with Node.js

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

问题描述

我已经从此处 http://nodejs.org/安装了node.js.在我的Windows8机器上.将示例服务器代码复制到了我的server.js文件中

I have installed node.js from here http://nodejs.org/ . in my windows8 machine. copied the example server code in my server.js file

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

然后打开node.js提示符并写入节点c:/node/server.js但什么也没发生.我是一个PHP开发人员,只是想尝试一下它,所以任何指导原则都将非常有帮助.

then opened the node.js prompt and written node c:/node/server.js but nothing happens. I am a php developer just trying hands on it, any guidelines will really be helpful.

推荐答案

您不需要进入node.js提示符,只需使用标准命令promt并编写

You don't need to go in node.js prompt, you just need to use standard command promt and write

node c:/node/server.js

这也有效:

node c:\node\server.js

,然后在您的浏览器中:

and then in your browser:

http://localhost:1337

这篇关于如何使用Node.js运行用JS编写的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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