Change directory in Node.js command prompt - node.js

I want to move to another directory in Node.js command prompt but when I open the Node.js cmd window it doesn't show me any path. Here is the screenshot of the Node.js cmd window:
Now if i want to change directory to D:\abc then how can i do it here?

That isn't the Node.js command prompt window. That is a language shell to run JavaScript commands, also known as a REPL.
In Windows, there should be a Node.js command prompt in your Start menu or start screen:
Which will open a command prompt window that looks like this:
From there you can switch directories using the cd command.

To switch to the another directory
process.chdir("../");

If you mean to change default directory for "Node.js command prompt", when you launch it, then (Windows case)
go the directory where NodeJS was installed
find file nodevars.bat
open it with editor as administrator
change the default path in the row which looks like
if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%"
with your path. It could be for example
if "%CD%\"=="%~dp0" cd /d "c://MyDirectory/"
if you mean to change directory once when you launched "Node.js command prompt", then execute the following command in the Node.js command prompt:
cd c:/MyDirectory/

Add the \d [dir] attribute to the cd command like this:
cd \d %yourdir%:\

Open file nodevars.bat
Just add your path to the end,
"%HOMEDRIVE%%HOMEPATH% /file1/file2/file3
Save file nodevars.bat
This work even with Swedish words

Type .exit in command prompt window, It terminates the node repl.

.help will show you all the options.
Do .exit in this case

Related

Alacritty: run a startup script?

I'm on Windows 10 and trying to run a startup script (vcvars64.bat) to setup the MSVC compiler before using the Alacritty prompt.
I have tried the -e switch with the command and also with the alacritty.yml shell: option, but both options open Alacritty, run the command, then exit.
How do I run a script on startup as the first command then continue into Alacritty?
Thanks,
Matic
What I ended up with is:
Specify program: cmd.exe in Alacritty alacritty.yml:
shell:
program: cmd.exe
Create a shortcut to Alacritty.exe and place it eg. in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ (so that it shows up in Windows search).
In properties for the shortcut, under target, specify:
"C:\Program Files\Alacritty\alacritty.exe" --command "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat >/NUL" && bash.exe
Modify Visual Studio path to whatever you have, and which varsall.bat you want to use.
The tricky part was how sensitive cmd.exe is regarding quotes. Eg., it does not work for me to specify an absolute path to which bash.exe to use, it would fail on the first whitespace in the path no matter how I tried to quote it. So make sure the correct bash.exe is first in your PATH (open plain cmd.exe and run where bash.exe to see order). Another solution is of course to create a shortcut to the bash.exe of your liking to a place without spaces in its path then specify it's absolute path (tested to work).

Open Cygwin.bat file in current working directory (Windows 10)

New to Cygwin and trying to launch the batch file from the current working directory. I've done similar things before for .exe files in Windows 10 using the Registry Editor (see link):
https://www.windowscentral.com/how-launch-bash-shell-right-click-context-menu-windows-10
My Cygwin.bat file looks like this:
#echo off
SETLOCAL
set HOME=C:\path\to\home
C:
chdir C:\cygwin64\bin
bash --login -i
ENDLOCAL
However, when I right click on a directory in order to "Open Cygwin.bat here", the terminal opens at C:\path\to\home. How can I make sure the terminal opens in the current working directory?
To obtain the expected result you need to use the chere package.
chere -i
is usually enough to create a proper Bash Prompt Here entry in Explorer left mouse button menu.
Please note that the usage of the cygwin.bat is not recommended anyway as does not use mintty as terminal

Run Perl script in Linux environment

I'm trying to run code on Linux environment
Here's the code (saved as hello.pl):
#!/usr/bin/perl
use strict;
use warnings;
print "Hello You\n";
Here's what I tried on my linux environment:
%perl hello.pl
I tried listing out the path starting from C:\Users\... and so on
I keep getting error that says:
Can't open perl script "hello.pl": No such file or directory
You have to be located in the same folder with the hello.pl in the "window" (aka terminal, or console) that you try to execute perl hello.pl.
On linux, you can determine the folder that you're in by issuing pwd.
If you're not in the same folder (the most probable cause of your error), you have 2 options:
Navigate to that folder with cd /path/to/your/script/location you have to replace the /path/to/your/script/location in the example, with your actual path
Execute the file with perl /path/to/hello.pl - of course, you have to replace the /path/to/ in the example, with your ac
Also, you can try and view the file from the console running a less hello.pl
In cygwin you might try: /cygdrive/c/Users/bonan/Desktop/perl/hello.pl.
Alternatively at your prompt try tying in just perl without hitting enter, and then drag the hello.pl file from its file explorer location into the terminal window. That should paste the full file path to the file as text into the command prompt. If you're using cygwin I forget it if properly pastes the path with forward-slashes, like /cygdrive/c/Users/bonan/Desktop/perl/hello.pl, or if it pastes what it would in cmd with backslashes as you've indicated you typed yourself.
The other thing to do that's relatively easy is right click the file and choose to open a terminal or shell here, which for cygwin you can get in your context menu by running chere -i once (it actually says "Bash prompt here" I think). And there's similar context menu options for cmd, powershell, an actual linux bash, or mac os x's terminal ... once you're in the same path as the file, you can just type perl heltab and autocomplete the filename assuming no other files in the same folder start with "hel".

Open Cygwin command in specified directory on windows

I use phpstorm and it's terminal facility.
In terminal section I typed F:\Projects\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico - so it uses Cygwin as terminal. But it opens it in home folder. Is it possible to open it in different folder? By typing a command or by doing something else.
Because I have a folder called F:\Projects\Local in this folder I have vagrant and I want to open phpstorm, open terminal within php storm and just type vagran up. I don't want to open cgywin again.
thanks
If you just want to open Cygwin with Mintty in the project directory then you can execute the command:
F:\Projects\cygwin64\bin\mintty.exe /bin/env CHERE_INVOKING=1 /bin/bash -l
This will avoid automatically changing to the home directory. See https://code.google.com/p/mintty/wiki/Tips#Starting_in_a_particular_directory for more information on this command.
If you want to use the embedded PhpStorm terminal, then you can modify the Shell path in the terminal settings. Open File > Settings... > Tools > Terminal. Replace the shell path with F:\Projects\cygwin64\bin\env.exe CHERE_INVOKING=1 /bin/bash -l. You may need to restart PhpStorm after this change.
Note: this is assuming that your Cygwin Root Directory is F:\Projects\cygwin64\.
For whome the above way ain't work anymore, like in PhpStorm v. 2016.3. The shell path have to be enclosed in quotes
"C:\Users\MyUser\.babun\cygwin\bin\env.exe" CHERE_INVOKING=1 /bin/zsh.exe
For the PhpStorm that I'am using (v10.0.4) in Windows 10 I use this command works:
D:\tools\.babun\cygwin\bin\env.exe CHERE_INVOKING=1 /bin/bash.exe
I'm using Babun which installs the Cygwin in D:\tools\.babun\cygwin.

How to start Gvim from Command Prompt?

I tried to start gvim using start command like this
start gvim.exe
But it doesn't work for gvim, although it does work for firefox.exe. My questions are-
How can I start gvim from command prompt?
Why start command doesn't work for gvim.exe?
Are there any additional parameter that I can use when starting gvim from command prompt?
Completely different, so a separate answer:
Actually, -- I just remembered -- Vim isn't normally added to the path variable, it's run through .bat files in C:\Windows.
From another answer on StackOverflow:
When you install gVim: Please make sure Create .bat files for
command line use is checked. It'll create several .bat files in
C:\Windows\:
C:\>cd %windir%
C:\WINDOWS>dir /b *.bat
evim.bat
gview.bat
gvim.bat
gvimdiff.bat
view.bat
vim.bat
vimdiff.bat
vimtutor.bat
This is because gvim.exe is not in your PATH list. If you know which directory gvim.exe resides, add this directory to your PATH list. This can be done by typing the following in an Explorer address bar:
Control Panel\System and Security\System
Then press Advanced system setings, then Environment Variables. The PATH is a list of directories separated by a ;.
Try typing just "gvim" instead of "start gvim.exe". That works for me. Vim isn't in my path environment variable.

Resources