2

Suppose you have an npm package that you want to be usable as a command line program, e.g. js-beautify.

When I install this globally, I see that there is indeed a Windows batch file that comes with it, in fact two slightly different batch files with the same name in different directories (and a shell script for when it's installed on UNIX).

But when I look at the js-beautify source on github, there's no sign of any batch file. Where does the batch file come from? I don't see any mention of such in the npm documentation.

rwallace
  • 31,405
  • 40
  • 123
  • 242

2 Answers2

4

This happens when you configure the "bin" property in your package.json as js-beautify does here. Specifically, npm install uses the cmd-shim module to create them as shown here.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
0

I would imagine that--in my case--C:\Program Files\nodejs\npm (the executable) is ultimately responsible for creating the operating system--specific differences like this. A Windows-based computer can't just run files without extensions like this and yet by adding npm.cmd into that same folder this is enough to allow Windows to behave enough like a UNIX box for this to work.

In theory, then, create your program in the UNIX world without an extension and then install it in the Windows world and let npm do its thing. It ought to bridge the gap by adding a .cmd or .bat file.

Michael Blankenship
  • 1,639
  • 10
  • 16