4

I am writing a basic command line utility using node in Windows. Here is the file kevin.js

#!/usr/bin/env node console.log("Hello"); 

Below is my package.json

{ "name": "kevin", "version": "0.0.0", "preferGlobal": "true", "bin":{ "kevin":"kevin.js" } } 

When I execute node kevin.js it works. npm link command also works fine. But when i try to execute my command kevin, it does not execute, instead opens the file in Notepad.

1
  • 3
    Windows does not understand the #!/usr/bin/env node part of your script. You have to run it as 'node kevin.js' Commented Jan 8, 2013 at 15:32

2 Answers 2

3

you can create kevin.cmd (or kevin.bat) with the command to run your tool (e.g.: node kevin.js) and put it somewhere in the system PATH. That's what most of the tools do (like uglifyjs, less, etc.).

Sign up to request clarification or add additional context in comments.

Comments

2

You can associate a file extension with a default "runtime" environment.

See my explanation on how to do it here: https://stackoverflow.com/a/6818266/330315

Once you have done it, you can simply type "kevin" in the commandline and it will be executed using node.js

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.