Javascript 在 Node 中使用命令行创建文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26343974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create file with command line in Node
提问by ckpepper02
So I'm attempting to do this Node.js tutorial, and it says to create three .jsfiles from the command line.
所以我正在尝试做这个Node.js 教程,它说.js从命令行创建三个文件。
touch server.js client.js test.js
touch server.js client.js test.js
Except I get the following error:
除了我收到以下错误:
'touch' is not recognized as an internal or external command, operable program or batch file.
'touch' 不是内部或外部命令,也不是可运行的程序或批处理文件。
Not sure what is wrong here. I've installed Node.js as well as npm and browserify. I've created the package.json file correctly.
不知道这里有什么问题。我已经安装了 Node.js 以及 npm 和 browserify。我已经正确创建了 package.json 文件。
I suppose I could go into the project directory, right click and make a new file that way, but that defeats the purpose doesn't it?
我想我可以进入项目目录,右键单击并以这种方式创建一个新文件,但这违背了目的,不是吗?
What is the actual command to create a new file in the command line?
在命令行中创建新文件的实际命令是什么?
I'm using Windows 7.
我正在使用 Windows 7。
回答by ltalhouarne
That command is for a unix environment. You can use the following to create an empty file with similar functionalities that touchhas in windows:
该命令适用于 unix 环境。您可以使用以下内容创建一个具有与touchWindows 中类似功能的空文件:
echo $null >> server.jsin the desired directory
echo $null >> server.js在所需目录中
回答by Hukmaram
You can use the following command:
您可以使用以下命令:
echo> index.js
回答by joews
touchis generally present on *nix platforms but not Windows. You will be able to follow the tutorial without it.
touch通常存在于 *nix 平台上,但不存在于 Windows 上。您将能够在没有它的情况下学习本教程。
The tutorial author is using it to create empty files. You could achieve the same by simply saving files with the same names using an editor.
教程作者正在使用它来创建空文件。您可以通过使用编辑器简单地保存具有相同名称的文件来实现相同的效果。
Alternatively, if you really want to use it in Windows, try Cygwin.
或者,如果您真的想在 Windows 中使用它,请尝试Cygwin。
回答by GeoMar
You can use : copy nul > Gulpfile.js
您可以使用:复制 nul > Gulpfile.js
回答by Nishat Lakhani
You can also use the following command:
您还可以使用以下命令:
copy con [filename.extension]
copy con [filename.extension]
[Note: Don't include square brackets]
[注意:不要包括方括号]
That's it!
就是这样!
回答by Sameesh Kumar
Follow the link For installation in Windows https://www.npmjs.com/package/touch-for-windowsInstallation In command prompt type: npm install -g touch-for-windows.
按照链接在 Windows 中 安装https://www.npmjs.com/package/touch-for-windows安装在命令提示符下键入:npm install -g touch-for-windows。
Usage After installing, you can run this application via the command line, as shown below.
用法安装后,您可以通过命令行运行此应用程序,如下所示。
C:\pythonapp>touch index.html Successfully created 'index.html'
C:\pythonapp>touch index.html 成功创建'index.html'
Worked for me
为我工作

