Javascript 节点REPL抛出语法错误:意外标识符
我是node.js的新手。在节点REPL中,一切正常。但有些事情改变了。当我尝试执行一个文件时,它会显示以下内容Javascript 节点REPL抛出语法错误:意外标识符,javascript,node.js,git,read-eval-print-loop,Javascript,Node.js,Git,Read Eval Print Loop,我是node.js的新手。在节点REPL中,一切正常。但有些事情改变了。当我尝试执行一个文件时,它会显示以下内容 D:\Projects-2015\uniqueva>node />node module.js SyntaxError: Unexpected identifier at Object.exports.createScript (vm.js:44:10) at REPLServer.defaultEval (repl.js:117:23) at
D:\Projects-2015\uniqueva>node
/>node module.js
SyntaxError: Unexpected identifier
at Object.exports.createScript (vm.js:44:10)
at REPLServer.defaultEval (repl.js:117:23)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
at ReadStream.onkeypress (readline.js:109:10)
我在module.js中有以下代码
var http = require("http");
http.createServer(function(request, response){
response.writeHead(200, {"Content-Type" : "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
..但即使我尝试只记录console.log内容,或者只是将文件留空,这也是同样的问题。。
您不能从节点应答中调用节点可执行文件。。。只有JavaScript语句/表达式
尝试
require('./module.js')
双击节点是否运行该节点
您必须从命令行运行node,并在命令行上指定命令node xyz.js
节点应该位于类路径中,或者在执行节点时使用完整路径。例如c:\work\nodetest\node.\xyz.js
在上面,我处理了与节点文件位于同一文件夹中的js文件 您的
module.js
文件中有什么?@Osukaa,我已经更新了我的问题。实际上我正在使用Git Bash执行节点脚本。那有关系吗?几天前它工作得很好!您当时可能没有输入节点REPL。没有理由它会在REPL中工作……好吧,那我该怎么做呢?如何从Git bash执行它?我手动删除了几个npm模块。不执行node
,只执行node module.js
var http = require("http");
http.createServer(function(request, response){
response.writeHead(200, {"Content-Type" : "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);