25
votes

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.

8
touch has nothing to do with node.js. See Windows equivalent of the Linux command 'touch'?undefined
Thanks for that link.ckpepper02
Working with node on Windows you really might want something like cygwin -> cygwin.com Just because most of the resources you see will refer to unix commands. Also, make sure you install apt-cyg when you install cygwin so you don't have to run the installer each time you want to add a package/command. It takes a little bit to get to where you want to be with it but I have found it to be worth it a million times over.Resist Design

8 Answers

51
votes

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

8
votes

You can use the following command:

echo> index.js
4
votes

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.

2
votes

You can use : copy nul > Gulpfile.js

1
votes

I know this is an old post, but the question is still relevant and there is a way to integrate the touch command into Windows, using the touch-for-windows npm package. It can be installed globally via node/npm with npm install -g touch-for-windows.

As someone who uses a pretty customized terminal across multiple machines, Cygwin didn't provide some of the other features I often use. The echo command (and accepted answer) provided by ltalhouarne works, but I felt was cumbersome to use. This npm package, though old, operates exactly in Windows as the touch command in *nux.

0
votes

You can also use the following command:

copy con [filename.extension]

[Note: Don't include square brackets]

That's it!

0
votes

Follow the link For installation in Windows https://www.npmjs.com/package/touch-for-windows Installation In command prompt type: 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'

Worked for me

0
votes

cd > filename.txt works too... if u create txt files, then it will have the file path on them. Just remember to delete them.