Default path in node.js terminal - node.js

Can i change default path in node.js terminal? I have my projects in one folder so every time i need type same path, it's not big problem but maybe it's easy to set ;)

You should check this out.
Basically, you can set the NODE_PATH environment variable to add a path of your other project. Then node will try to look there to load modules and you don't have to give a relative or absolute path to a node module.

Related

Copying shell file to path

I'm new to WSL and Linux, but I'm trying to follow installation instructions for rhasspy (https://rhasspy.readthedocs.io/en/latest/installation/#windows-subsystem-for-linux-wsl). I have run the make install command successfully and the next step says I should copy rhasspy somewhere in my path but I can't quite figure out what copying to path means.
When installation is finished, copy rhasspy.sh somewhere in your PATH and rename it to rhasspy.
I added it to path but nothing changed so I was wondering if there is something I'm doing wrong. Right now when I run rhasspy on wsl it says rhasspy.sh: command not found. Any help would be really appreciated!
What it says is, put it in some place where the system will look for it when you type its name without full path in the shell.
There is an environment variable PATH that contains all those locations, separated by a :. (Check out echo $PATH.)
So, the author of these instructions leaves it up to you whether...
You want to copy the file to a location of your choice that is already in the PATH, such as /usr/local/bin or ~/bin.
Usually ~/bin is a good choice because it is per-user and doesn't pollute the system.
(Note that the directory ~/bin is added to the PATH by your .profile file only if it exists, so if you don't have this directory yet and create it now, you need to start a new login shell or run . ~/.profile1 before you can use it.)
- OR -
You want to create a new directory specifically for this application (say for example ~/opt/rhasspy) and append that directory to the PATH variable.
This can be done by adding the line export PATH=$PATH:~/opt/rhasspy to your ~/.profile file. Then, start a new login shell or reload the file using . ~/.profile1 for the changes to take effect.
If the directory in which this file is currently located is OK for you to keep permanently, then you can also just add that directory to the PATH instead of creating a new one.
Note: The PATH always contains directory paths in which the shell will look for executable files. It does not contain the actual file paths!
1: Yes, technically it is "cleaner" to log into a new shell or to run that one export statement manually instead of using . ~/.profile because the latter will apply things a second time that were already done before, so for example it can end up with the same directory in the PATH multiple times in the current session. In most cases that is fine though.
PATH is an environment variable. When you launch env, you see the list of known environment variables on your system.
In order to add something to your PATH variable, you need to take the variable, add the mentioned directory (preceeded by a semi-colon, most probably, as a separator) and store this again as the PATH variable. This can be done as follows (own example):
export PATH=$PATH:/home/this_user
the "PATH" it is referring to in linux is just inside the folder called /usr/bin. when you type a command into the terminal it looks for a program with that name inside the location. im not sure if this is the PATH you are looking for but hope it helps

Add new libraries to PATH in node

Im trying to use 'node-fluent-ffmpeg' to get the first frame of a video. I added 'ffmpeg' to my node-modules because it was a prerequisite for 'node-fluent-ffmpeg,' however, in my logs it says "cant find ffmpeg." I dont understand the second paragraph it the 'node-fluent-ffmpeg' documentation where it talks about this. What are they referring to by PATH and how do i properly connect these two libraries?
When you type a command like dir or ls, your system looks in a set of configured directories for that binary. PATH refers to the variable that holds the list of directories.
If the ffmpeg binary is not in a directory on your shells PATH, then you have to set the path explicitly when you run node. This is done with the FFMPEG_PATH and FFPROBE_PATH environment variables.
You check if the binaries are on your path with which.
$ which ffmpeg
/usr/local/bin/ffmpeg
$ which ffprobe
/usr/local/bin/ffprobe
If which doesn't return a path or your app is running under a different shell environment (like a service would), you can set those module variables specifically when running node.
FFMPEG_PATH=/usr/local/bin/ffmpeg \
FFPROBE_PATH=/usr/local/bin/ffprobe \
node whatever.js
In your case it will be the full path to the node_modules directory you put the ffmpeg and ffprobe binaries in.

Where is node repl default directory and how to change it?

I'm reloading my script a lot and would like to change the default directory where node repl is looking at so that I don't have to provide the whole path.
Is that possible?
The node.js REPL uses the current working directory (the directory in which you invoked the REPL) as a base when you use relative paths.

Adding a permanent value to $PATH on Raspbian

I am quite new to Linux so I'm sorry for my newbie question,
but for about and hour now I'm trying to add Node.js to $PATH with no luck :(
I've used the following line to add Node
PATH=$PATH:node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
it worked, but when I logged off the terminal and logged in again, the path disappeared.
Later I tried adding the same line to .profile , .logins.defs and .bashrc.
All didn't work so I removed the line.
Please help me with this!
P.S , when I added the line to .profile I was able to call Node, but when I changed my directory in order to navigate to a Node project directory, I received the following error:
-bash: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin/node: No such file or directory
You should add an absolute path, not a relative one. You added this to your path: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin. That's a relative path, not an absolute one (absolute paths start with a /). You can change your line to:
PATH=$PATH:DIR/node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
where DIR is the full path of the directory containing node-v0.10.24-linux-arm-armv6j-vfp-hard.
It's probably a good idea for you to read a bit on how this all works - it's not that complicated once you see it explained. See https://superuser.com/questions/238987/how-does-unix-search-for-executable-files for an example.
You have $HOME already set to your home directory.
So you can use this in your .profile:
PATH="$PATH:$HOME:$HOME/bin:$HOME/node-v0.10.24-linux-arm-ar‌​mv6j-vfp-hard/bin"
If you set it as an absolute path you will not be able to copy that .profile to another user who is set up similarly.
I see there is another question that deals with installing node.js on Debian - and must admit I am surprised it is installed per-user. So if you do the install for another login you might want to copy your .profile to the new login to solve this same issue. There would be no per-user editing required if you use the $HOME variable like this. Just a simple copy or cut and paste.
For reference, here is that other question/answer: install node.js on debian

Choosing between multiple executables with same name in Linux

The system I am using has gnuplot installed in /usr/bin. I don't have root, but I needed a newer version of gnuplot, so I installed it to $HOME/usr/bin.
I added $HOME/usr/bin to my path, but it still executes the one in /usr/bin if I just use the gnuplot command. I'd rather not have to specify $HOME/usr/bin/gnuplot every time I have to use it.
How do I tell Linux to use the one in my home directory, and not the one in /usr/bin?
Executables are found in PATH order. You need to prepend ${HOME}/usr/bin to your path, like so:
export PATH="${HOME}/usr/bin:$PATH"
Executables are found in PATH order. Your PATH apparently is set up such that /usr/bin precedes ~/usr/bin/.
Besides modifying the PATH as has been explained, you can also use aliases like this (in BASH)
alias gn=$HOME/usr/bin/gnuplot
then you just run it with
gn
What Bombe says is ok. I would add that you should declare your user specific PATH entries inside your user's bashrc ($HOME/.bashrc), so your PATH settings only apply to your user.

Resources