Create file with command line in Node

2019-03-23 09:16发布

So I'm attempting to do this Node.js tutorial, and it says to create three .js files from the command line.

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.

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.

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.

4条回答
做个烂人
2楼-- · 2019-03-23 09:25

That command is for a unix environment. You can use the following to create an empty file with similar functionalities that touch has in windows:

echo $null >> server.js in the desired directory

查看更多
男人必须洒脱
3楼-- · 2019-03-23 09:25

You can also use the following command:

copy con [filename.extension]

[Note: Don't include square brackets]

That's it!

查看更多
放我归山
4楼-- · 2019-03-23 09:40

touch is generally present on *nix platforms but not Windows. You will be able to follow the tutorial without it.

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.

查看更多
我命由我不由天
5楼-- · 2019-03-23 09:41

You can use : copy nul > Gulpfile.js

查看更多
登录 后发表回答