简体   繁体   English

为什么 Node.js 无法在终端中运行我的 JavaScript 代码?

[英]Why Node.js cannot run my JavaScript code in the terminal?

在此处输入图像描述

Can anyone please tell me why my javascript code cannot be executed?谁能告诉我为什么我的 javascript 代码无法执行? What is Uncaught SyntaxError: Unexpected Identifier?什么是未捕获的 SyntaxError:意外的标识符?

You have a > before your text cursor.您的文本 cursor 之前有一个> This means that you're already in Node .这意味着您已经在 Node 中

Right now, what's happening is you're telling Node to run the following JavaScript:现在,发生的事情是您告诉 Node 运行以下 JavaScript:

 node index.js

which, of course, is not valid JavaScript.当然,这不是有效的 JavaScript。

You need to exit Node so that the standard terminal is displayed, such as cmd or powershell (press Control-C a couple times)您需要退出 Node 以便显示标准终端,例如 cmd 或 powershell(按 Control-C 几次)

在此处输入图像描述

Then you can type in node index.js .然后你可以输入node index.js If you're in the same directory as the index.js file, it'll execute.如果您与index.js文件位于同一目录中,它将执行。

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

相关问题 为什么这个JavaScript代码在Node.js优化之后运行得更慢 - Why does this JavaScript code run slower after Node.js optimization 为什么我的代码可以在标准 Node.js 文件中运行,而不能在 AWS Lambda 函数中运行? - Why can my code run in a standard Node.js file, but not in a AWS Lambda Function? 为什么节点不能在我的终端或浏览器中运行javascript函数? - Why doesn't node run javascript functions in my terminal or browser? 为什么我的 javascript ajax 代码返回未定义的 XMLHttpRequest GET 响应? - 在 Node.js 中运行 - Why is my javascript ajax code returning undefined for the XMLHttpRequest GET response? - running in Node.js 用Javascript编写异步方法(代码在Node.js中运行) - Writing an asynchronous method in Javascript (Code run in Node.js) JavaScript 代码未按预期顺序运行(Node.js、MongoDB) - JavaScript Code does not run in wanted order (Node.js, MongoDB) 为什么 Node.js 需要 JavaScript 前端框架才能运行? - Why JavaScript frontend framework is needed for Node.js to run? 在Visual Studio Code的集成终端中使用node.js打开JavaScript代码 - Opening JavaScript code with node.js in Visual Studio Code's integrated terminal 为什么这段代码卡住了node.js - Javascript上的Bug? - Why this code stuck node.js - Bug on Javascript? 从终端在 node.js 文件中运行单独的函数 - Run separate functions in node.js file from terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM