首页 > 解决方案 > 无法使用终端执行我的 node.js 代码

问题描述

我已经安装了 Node.js 版本 10.16.0 LTS。我在 cmd 中运行“node -v”命令来检查它是否安装正确。

创建了一个文件 hello.js 在同一目录下运行 cmd

错误消息说: D:\nodeJS>node

node hello.js 抛出:node hello.js ^^^^^ SyntaxError: Unexpected identifier

我在 .js 文件中编写的唯一代码行是:console.log("hello");

for(var i = 0; i < 10; i++){
    console.log("hello");
}

标签: node.js

解决方案


您在节点 REPL 中运行它。按 control + c 两次退出 Node REPL。然后你运行命令node hello.js


推荐阅读