繁体   English   中英

在节点中执行js文件

[英]Executing js files in node

我有一个具有以下内容的Hello.js文件。

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, "mysite.com");

console.log('Server running at http://mysite.com:1337/');

我转到命令提示符,输入节点...

我如何在节点console执行此Hello.js

当我输入node Hello.js ,我一个人....

http://imageshack.us/photo/my-images/801/hellor.png/

您的语法错误,您需要:

D:\Node > node Hello.js

您当前正在做的是与节点启动交互式会话,即

$ node
> console.log("hello"); # I typed this
hello
> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM