How to run the file when the package is installed globally

Here is the Package link.
I have added bin property in the package.json as the file which needs to run as node in order to run it. Package.json link.
When I installed this package as global and running the command which is mentioned in bin it is simply opening the file in the editor. It should run that file not open it in the editor. Any help here

You need to make the file executable. Add a “hash-bang” line as the first line of the javascript file to tell the shell how to run it:

#!/usr/bin/env node

And make the file executable:

chmod a+x dist/cli.js
1 Like

Great Its working …Thanks a lot man.

. what about that chmod a user cant change the permission after installing the package…so any suggestion with this. and is it neccessay ?

1 Like

Actually the chmod only matters when you are running it locally without having done an install, so a potential issue for developer but not for publish. (Was bit hasty with that info sorry.)

Ohh…thanks for that…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.