[英]When i try to create a new file using nodejs i get an error
The video just said open cmd, type node and press enter then type touch script.js and it'll create a js file but I'm getting this, I'm using window.视频刚刚说打开 cmd,键入 node 并按回车键,然后键入 touch script.js,它会创建一个 js 文件,但我明白了,我使用的是 window。
Uncaught SyntaxError: Unexpected identifier
> touch script.js
touch script.js
^^^^^^
I had the same issue ^^;我有同样的问题^^; For MAC user.
对于 MAC 用户。
You are currently in your node interpreter you need to exit it and then run the Unix commands, touch script.js你目前在你的节点解释器中你需要退出它然后运行 Unix 命令,touch script.js
To exit node退出节点
To run Unix command运行 Unix 命令
2.Type touch script.js
I think you need to first create a file called script.js.我认为您需要先创建一个名为 script.js 的文件。
-> for creating empty file -> 用于创建空文件
touch script.js
-> enter your node commands for eg -> 输入您的节点命令,例如
console.log("Hello world").
->then run node script.js
. -> 然后运行
node script.js
。
If you rune node and type enter, you will enter into node's REPL mode where you can execute and try all the commands node offers node REPL tutorial , usage of node REPL mode如果你运行 node 并输入回车,你将进入节点的 REPL 模式,你可以在其中执行并尝试节点提供的所有命令节点 REPL 教程, 节点 REPL 模式的使用
NOTE:- when running node script.js make sure you are in the correct directory.otherwise you may get an error similar to "file not exist" as node would not be able to find your script.js if you are not in the right directory.注意:- 运行 node script.js 时确保你在正确的目录中。否则你可能会收到类似于“文件不存在”的错误,因为如果你不在正确的目录中,node 将无法找到你的 script.js目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.