0

On RHEL I have put various executable files in ~/.local/bin eg. nvim.appimage. As ~/.local/bin is in my $PATH variable I can call nvim.appimage from any directory which is great.

I want some node apps to be able to be called from any directory, for example ESLint. These are not binaries but are directories with a lot of files and directories inside. Which directory (presumably in $PATH) should they be in so that I as a user but not other users can call them from any of my directories? Also how should they be invoked.

As an example, I have put the cowsay node app into ~/.local/bin I can invoke it like this from any of my directories:

$ node ~/.local/bin/cowsay/node_modules/cowsay/cli.js moo

(I can actually omit node from that command as cli.js has #!bin/bash/env node at the top.)

I would like to be able to invoke cowsay from any of my directories with a simple command eg cowsay

I know that a lot of node apps are not intended to be run from the command line but some are. In particular I am having great difficulty to get neovim with Ale to recognize some node linters like ESLint. Perhaps if I can sort the cowsay issue out I may be able to move on to ESLint with neovim. I am hoping that if I can get ESLint invokable from a location in $PATH it might be usable by neovim / Ale.

romainl
  • 186,200
  • 21
  • 280
  • 313
user3425506
  • 1,285
  • 1
  • 16
  • 26

1 Answers1

1

Can this achieve what you expected ?

mkdir ~/.local/nodexe
cd ~/.local/nodexe
ln -fs ../bin/cowsay/node_modules/cowsay/cli.js cowsay
PATH=$PATH:~/.local/nodexe

Assuming you have #!bin/bash/env node in cli.js, then you can run by typing cowsay moo

Philippe
  • 20,025
  • 2
  • 23
  • 32
  • that does work. I have a feeling it is not an approach which will help neovim / Ale recognize linters like ESLint. The problem is I don't have a clue how to get that working. – user3425506 Feb 14 '22 at 17:45
  • If you put a symbolic link in ~/.local/nodexe for ESlint, it should work. – Philippe Feb 14 '22 at 18:13
  • That worked too with reservations. When I opened a javascript file with vim in a directory with nothing else in it after creating the symbolic link to eslint it now got a connection with eslint. Unfortunately it was a warning saying I needed an eslint config file in the directory and I should run npm init @eslint/config. When I did, it installed a node_modules directory in my previously nearly empty directory. The node_modules directory had eslint and many other directories inside it. So, I now think that directory is using its local eslint not the one in ~/.local/etc/etc. It is linting! – user3425506 Feb 14 '22 at 19:36
  • When I ran npm init @eslint/config (see previous comment) I got a message saying I needed a dependency and I chose to install it. I repeated everything but this time I chose not to install it. This time node_modules was not installed. I only have 3 files in the directory: badjs.js, .eslintrc.json and package.json. Now when I invoke nvim from within the directory on badjs.js the errors in badjs.js show up exactly as they should. So, vim must be getting eslint from the symbolic link in ~/.local/nodexe. That is great although I ought to find out about why my config requires eslint@latest... – user3425506 Feb 14 '22 at 23:17