Jes*_*ing 10 javascript node.js
我有一个基本的node.js设置,但我想我错过了一些东西.
我的main.js:
var a = require('./another.js');
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200,
{
'Content-Type': 'text/html'
});
response.write(a.saysomething('Hi there!') + '<br />');
response.end();
}).listen(27182);
console.log('Server running at http://127.0.0.1:27182/');
Run Code Online (Sandbox Code Playgroud)
我的another.js:
exports.saysomething = function (str) {
console.log('in saysomething!');
return str + ' hey there!';
}
Run Code Online (Sandbox Code Playgroud)
问题是我的控制台输出了in saysomething!两次.我错过了什么吗?当我刷新页面时,我只期望一个in saysomething!.
Jus*_*mas 31
除了您正在点击的网址之外,您的浏览器可能还会尝试获取favicon.ico.尝试在命令行上执行命令:curl http://127.0.0.1:27182/
此外,您还可以添加日志记录request.url.这将显示您正在请求的网址.
| 归档时间: |
|
| 查看次数: |
5457 次 |
| 最近记录: |