I am using NodeJS version 4.2.1
I want to know the command for clearing the NodeJS REPL console history completely so it doesn't show previously executed commands when Up or Down arrow keys are pressed.
Any suggestions ?
The answer is actually simple :)
On Windows (my version is 10):
go to user folder: cd %userprofile%
empty file named .node_repl_history (in my case with vim text-editor) OR you can simple run: echo. > .node_repl_history and it will have same effect.
Per the nodejs documentation which can be found at the following link:
nodejs repl
Environment Variable Options
The built-in repl (invoked by running
node or node -i) may be controlled via the following environment
variables:
NODE_REPL_HISTORY - When a valid path is given, persistent REPL
history will be saved to the specified file rather than
.node_repl_history in the user's home directory. Setting this value to
"" will disable persistent REPL history. NODE_REPL_HISTORY_SIZE -
defaults to 1000. Controls how many lines of history will be persisted
if history is available. Must be a positive number. NODE_REPL_MODE -
may be any of sloppy, strict, or magic. Defaults to magic, which will
automatically run "strict mode only" statements in strict mode.
Persistent History
By default, the REPL will persist history between
node REPL sessions by saving to a .node_repl_history file in the
user's home directory. This can be disabled by setting the environment
variable NODE_REPL_HISTORY="".
I think you might be looking for console.clear(). At least as of v8.3.0 https://doc.codingdict.com/nodejs-ref/console.html#console_console_clear :)
Related
I'm trying to write scripts that allow me to switch my development environment.
I want to write a script so that I can call it like this:
switchdevA
and inside that script, one of the things it should do is switch to node v16.16.0
inside switchdevA i have the following:
#!/bin/zsh
source ~/.zshrc
nvm use v16.16.0
the output says that I have switched to node v16.16.0, but when I type node -v I get:
v12.22.12
I can fix if i call source switchdevA, but should I do it that way? Other things like java don't seem to require me sourcing. In addition, the installation is lost if I start a new zsh session, ideally it should install for the current session and all future sessions.
What's the best practice around this?
A quick clarification: NVM is a shell function and not an executable.
You've correctly identified that source switchdevA will work properly, and that it is different from other version managers.
One solution is to keep your script as is, and create an additional shell alias that will run source scriptname (e.g. alias switchdevA='source switchdevA').
Unfortunately, for your other request to keep the current Node version in all future shell sessions, that can’t be achieved unless you have some persistence added in. For example, a simple file named ~/.lastnode. Then, in your ~/.zshrc, you would have a line nvm use "$(cat ~/.lastnode)" (which comes after the initialization of NVM). Finally, the original script would need to include a line at the bottom to update the last selected Node version: nvm version > ~/.lastnode.
When I start neovide from my applications and run :checkhealth I get errors that node and other commands are not available. But when I start it from my terminal there is no error for those commands. I tried to copy and modify the neovide desktop file to start just nvim and see if there if something wrong with my my neovide installation. But also starting just nvim as application prints the same errors.
I'm using linux with plasma desktop
TL:DR; add a path variable
Depending on your configuration, nvim will need to know the environment to run some executables (like it is with node in your example). An easy solution is to add the path variable to the exec command in the according .desktop file. I remember that I had the same issue with node not being recognized in a configuration using my plasma installation. On gnome node was recognized and healthchecks were good, so I thought I didn't need the extra path. Later on I realized that I had trouble with other commands. E.g. when using fdfind to complete path commands. Again I had to search what the reason was and it also was the missing path.
To give an example, let's say you are using zsh and want to start neovide with multigrid enabled, the Exec line in your desktop file could look like:
Exec=zsh -c "source ~/.config/zsh/.zshrc && neovide --multigrid %F"
In the Node (v16.7.0) REPL, Node tries to evaluate my statement before I've finished typing it. For example, if I type 2 + 2, it displays a faint 4 on the next line before I hit the Enter key. Is there a way to disable this behavior? For most cases, it's not a problem; but when I'm performing expensive operations, the REPL lags or freezes up as I'm trying to finish typing my statement. To be clear, the problem is not that the interpreter is printing the output; it's that it's trying to evaluate my statement before I finish typing it. Thanks in advance for your help!
The REPL library calls that a preview (search for preview in the link for more info). I'm not aware how to launch the default node REPL with command line options (or some other kind of configuration options) so that previews are not shown, but the REPL itself is a library you can use, with all the defaults (or whatever you prefer) and removing previews - for this check the REPL library options.
A basic example is creating this script:
#!/usr/bin/env node
const repl = require('repl');
repl.start({
preview: false
});
Make sure you also have it as executable (in Linux/Mac from the command line it would be with chmod +x name-of-repl-script from the terminal), and well, run that script instead of node directly.
Alternatively you can run the script with node name-of-repl-script (here, assuming node is the NodeJS REPL executable and that it's in the path).
I typed on my terminal the following command :
export BACKEND_URL="<confidential>"
. Apparently it was working, but when I turned off my computer and turned on again, I realized that this env var named BACKEND_URL It was not saved anymore. Why this happened ?
First of all:
This question would better fit the Unix&Linux StackExchange site than this web site.
However:
By typing "BACKEND_URL="<confidential>"" you set a variable which is valid for the currently running shell (terminal window) only.
If you close the terminal window, the variable is gone. The variable is also not valid for programs started from that terminal window.
If you add export (as you did), the variable is also valid for programs started from that terminal window.
However, still it is not valid for other terminal windows and if you close the teminal window, it will be gone.
When using one of the standard shells, you can add variables to the .profile file in your home directory.
When you are using bash, you can also add variables to the .bashrc file in your home directory.
I work in an environment where we all log in as ourselves, then sudo to a common user. (Bleah). I'm starting to use emacs and would like to specify my own .emacs file at launch. What I think I want is to specify the location of .emacs with an environment variable, but I don't see any way to do that in the emacs documentation. Is there one?
As an alternative, perhaps I need to learn elisp and conditionally load my own file out of the common .emacs file located in /home/common_user/.emacs? In my case, I already have an environment variable SUDO_USER set to my name 'lcuff', and an environment variable MY_CONF set to /foo/bar/blah/lcuff, wherein I'd like to store my own .emacs file. How would I do this?
Thoughts and advice appreciated.
See:
C-hig (emacs) Find Init RET
Failing anything else, you can specify $HOME for a command with env:
env HOME=/foo/bar/blah/lcuff emacs
Invoking emacs with the -u option will seek the init file for the given user, so
emacs -u Leonard
will run emacs with your emacs initialization file, even if you are logged in as another user.
You can tell emacs to load the init file of your choice by saying:
emacs -q -l /path/to/my/preferred/.emacs
It's a little bit tricky working out who emacs thinks you are. From info:
More precisely, Emacs first determines which user's init file to use.
It gets your user name from the environment variables LOGNAME and
USER; if neither of those exists, it uses effective user-ID. If that
user name matches the real user-ID, then Emacs uses `HOME'; otherwise,
it looks up the home directory corresponding to that user name in the
system's data base of users.
So I'd start first with finding out who emacs thinks you are, by starting emacs
without loading any init files:
emacs -q
and then find out where emacs thinks your init file is:
(locate-user-emacs-file "yourrealusername")
I think on a fresh home environment it will default to
~/.emacs.d/yourusername, but that should help you decide where best to place
the init file.
An important point is that it's pretty good practice to have an emacs user
directory rather than just a startup file. There is a heap of extra guff
that emacs needs to keep track of (package management, customized settings,
backup files, dictionary, manually inserted lisp code etc etc) and I find it extremely useful to put all
this stuff in the one spot. Emacs looks in ~/.emacs.d/init.el if it doesn't
see ~/.emacs or ~/.emacs.el on the system. Make sure you don't have ~/.emacs
still.
Create a new file called ~/.emacs.d/init.el
Put this in it:
(setq user-emacs-directory "~/.emacs.d/")
(message "This is my init.el file and noone elses!!!")
(inhibit-default-init) ;; there might be a default.el lurking somewhere
If emacs got your username and home right, you can then restart with:
emacs -u therealme
or, if it stuffs up the environment variables
env HOME=/this/is/my/home USER=blah emacs
There just might be a site-start.el somewhere that might get loaded before
your init.el. If you suspect this, loading emacs with the --no-site-file
option will nuke this.