Kevin
Kevin

Reputation: 23634

Node: Command line utitly in Windows

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.

Upvotes: 4

Views: 1779

Answers (2)

Dziad Borowy
Dziad Borowy

Reputation: 12579

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.).

Upvotes: 3

user330315
user330315

Reputation:

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

Upvotes: 2

Related Questions