简体   繁体   English

当我尝试使用 nodejs 创建一个新文件时出现错误

[英]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退出节点

  1. Press Ctrl+C twice or type.exit按 Ctrl+C 两次或键入 .exit

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.

相关问题 当我尝试运行带有jQuery的文件时出现nodejs错误 - nodejs error when i try to run a file with jquery in it 当我尝试用我的 nodejs Dapp 添加 ipfs 文件时出错 - Error when I try to add ipfs file with my nodejs Dapp 当我尝试创建 react 项目时出现错误 - When i try to create react project i get error 使用NodeJ和sed创建新的Kubernetes配置文件时出错 - Error when using the NodeJs and sed to create the new Kubernetes config file 当我尝试使用 docker-compose 为 nodejs 和 mysql 应用程序运行 docker 容器时出现端口使用错误 - I get port in use error when I try to run the docker container for the nodejs and mysql application using the docker-compose 当我尝试使用 createReadStream 使用 apollo-server 上传文件时出现此错误, - I get this error when I try to upload a file with apollo-server using createReadStream , 当我尝试在Couchbase Node.js服务器上运行简单测试时,出现“参数错误”错误 - I get “Incorrect argument” error when i try to run a simple test on couchbase nodejs server 当我尝试连接到 nodejs 中内置的服务器时,出现“错误:连接 ECONNREFUSED ip:4000” - I get "Error: connect ECONNREFUSED ip:4000" when I try to connect to the server built in nodejs 由于我是 nodejs 新手,我无法使用 nodejs 在 aws lambda 的 tmp 位置创建文件 - As I am new to nodejs, I am Unable to create file in tmp location of aws lambda using nodejs 当我尝试创建一个新的 angular 项目时出现以下错误 - I am getting following error when I try to create a new angular project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM