【发布时间】:2015-05-23 23:42:08
【问题描述】:
过去 2 天我花了更多时间阅读 50 多篇文章和视频以了解 node.js,安装后现在我可以通过http//:localhost:3000/ 在浏览器中看到结果但我在很多情况下感到困惑,我在下面描述。
我的所有工作都在我的共享托管服务器上完成,我在其中保存我的网站:www.myweb.com
在每篇关于 node.js 的文章中,他们都在教如何在本地 PC 服务器中通过 http//:localhost:3000/ 在浏览器中通过以下代码获取结果。
test.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
但我的问题:
如果我在浏览器中使用http//:www.myweb.com/test.js`,上面的代码会是什么?
如果是本地电脑,我们写在npm
node test.js,但是如果是托管服务器,当任何clint 像http//:www.myweb.com/test.js这样打开页面时如何工作呢?在 php 的情况下,我们使用 include ("head.php") 从该页面获取某些内容,但在这种情况下,如何调用 node.js。
【问题讨论】:
-
转到
http://www.myweb.com:3000
标签: javascript php node.js