Answer the question
In order to leave comments, you need to log in
How to run a module from the command line with one command?
Right now I have a console application. I can only work with it in its directory or by specifying the path to the script. node myscript.js // or node myscript
I want to be able to reach it from anywhere, for example myscript <args>
Do I need to create an npm package, install it globally?
Please help, I can't figure it out
supportInfo = {
system:"windows 10",
node:"v4.4.7",
npm:"v2.15.8"
}
Answer the question
In order to leave comments, you need to log in
I have found a solution. It's simple :)
I added to package.json
"preferGlobal": true,
"bin": {
"spp": "spp.js"
},
для варианта под линукс я создал следующий файл с именем script
:
#!/usr/bin/env node
console.log("Hallo!");
$ ./script
Hallo!
$PATH
(я предполагаю, что мы говорим о линуксе) либо же добавить в $PATH
директорию, в которой лежит ваш скрипт. тогда вы сможете его вызывать из любого места. обычно для этого скрипт ложат или линкуют в ~/bin
директорию
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question