How to make custom global command in VS Code terminal? - visual-studio-code

I just installed MongoDB. Instead of writing annoying cd to mongod.exe every time I want to run MongoDB, I want this file to be available as a global command, so that it runs regardless of the directory I'm in, like node or npm or git. How do I accomplish this for VS Code terminal?

There are different approaches to start mongod.exe:
You could add mongod.exe to your system's PATH variable (like git, npm etc.)
You could create a script (for example a .bat) file in your workspace directory, that contains
Start "path/to/mongod.exe"
If you want to start the mongod.exe via a vscode command like Strg + P for the user settings, you need to write an extension and register a command.

Related

Set the path in portable vscode installation powershell terminal

I have multiple versions of vscode installed on my system with portable mode. I start each of them via a desktop shortcut. Since they are in portable mode, their installation directories are not in the default PATH variable.
When I make a new powershell terminal window, the portable vscode directory is not on the path. I need the command "code" in the terminal window to run the same vscode version that the terminal shell is running in. In other words, if I am running a portable vscode, and I open a powershell terminal and type the command "code", I want it to run the code.exe file that is the same as the vscode I am running it in, and not a different one, and not get the "object not found" message. For various reasons I do not want to have to type the full path.
So, in essence, I want to add a directory to the path variable when vscode starts up, with that directory being the base directory of the vscode itself.
You need to set this in: File/Preferences/Settings then select Workspace, there go to: Terminal/Integrated:Cmd and there specify An explicit start path where the terminal will be launched.

Mongodb database tool commands wont take effect

I want to use commands such as mongodump/mongorestore/mongoexport on my local windows computer and have therefor downloaded the .msi extension version of mongodb database tool and also executed the .msi so it could be installed.
But what do i do now to start using the commands. I cant find any documentaions of this. Is there something i have to configue?
When i execute a command like mongodump on my system command line i get the response:
'mongodump' is not recognized as an internal or external command, operable program or batch file.
Do i maybe have to execute the command from a certain dir location?
Look for the highlighted folder on your system. When you install the database tools this folder is created. Inside this folder there is a bin folder which contains all the commands you are looking for.
Once you find this folder then navigate to bin folder. And open a command prompt at that location. And try running the commands.
Alternatively:-
You can set PATH to bin folder and then you will be able to run the commands from anywhere.

bash: mongo: command not found

I installed mongodb on my system, but when I go to bin directory using Git and type mongo, this happens.
What shall I do?
The problem can solve if you add MongoDB path in the system variables:
Go to this path "Control Panel\System and Security\System" on the left you should see some options click on "Advanced system settings" after this click on "Environment Variables" at the System variables should be one option "Path" click that option and "Edit" it, add "New" variable on this system, in my case, is "C:\Program Files\MongoDB\Server\4.2\bin" and save this change.
if you're using git bash, use the following command
$ ./mongo
I've just had the same problem and did this to solve it. I hope it helps (late, but to be sure it is answered).
Open GitBash and type the following:
1) cd.. // to go to the root directory.
2) touch .bash_profile // creates a hidden file to set up the shortcut
3) notepad .bash_profile // this opens that hidden file with notepad. You can also do it with VIM if you want to master you command console skills...
4) paste these two command lines:
alias mongod="/c/Program\ Files/MongoDB/Server/4.0/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
!!! Check that your files are also in the same route as these. If not, modify what's needed. Mind the space between "\ Files" because this gave trouble too. You may need to change the version in case you don't have 4.0.
5) Save the file. Close Notepad.
6) At Gitbash again: CRTL + C, and close the console.
7) Open Gitbash again, go to the root, and type: mongo --version. If you see something like: MongoDB Shell version v4.0.10... you've been successful (see image). If not, check the route of the document you've put into the bash profile, and be sure to fully restart the bash console after.
Mongo install success
Hope that helps!
Use mongosh intead of mongo.
This solved my problem using docker
In later versions of this, you have to download mongo shell. Once you downloaded if zip extracts the files and moved folder to your program's folder. Renamed the folder mongosh. Copy the path and added to your environment variables path. it should look like this C:\Program Files\mongosh\bin. Next, if you haven't done so already. Create data folder in your root directory in my case windows c drive. Create a subfolder in the data folder called db. make sure this folder is in the root directory and not in the program's folder. Once this is done, close all the prompt windows and run again mongod and again run now not mongo but mongosh, and it will allow you to type in your code. I had to delete my previous created data folder that i created previous to installation of MongoDB hope this helps.

Can't put MongoDB in my PATH

I'm trying to include MongoDB in my PATH on Ubuntu 14.04 by issuing this command:
export PATH=/home/<my-user-name>/mongodb-linux-x86_64-ubuntu1404-3.2.4/bin:$PATH
It seems OK but when I restart the terminal it can't find it again. Do you have any idea what's going on?
export commands only work for the current terminal window.
You should add this command to one of the files that run when you start your terminal session.
Your best choice would be to add this line to a file called ~/.profile, since it will run regardless of the shell you are using.

Reloading/Recompiling/Refreshing .beam files inside a terminal

I use Eclipse and Erlide to develop in Erlang. To run the software I enter the ebin/ directory with my terminal since I don't like the console Eclipse provides. However after each change I have to exit and re-enter erl in the terminal to reload the .beam files that have been changed. Eclipse automatically generates new .beam files into the ebin/ directory after every save.
I know I can manually compile it with the c(filename) command, but that would require me to move to the src/ directory, compile the files, and move them back to the ebin/ directory. This requires a lot more work that just exiting and entering the Erlang terminal.
I have heard of makefiles, but I don't know if they can be ran from within an Erlang terminal.
The reason I don't want to exit the terminal is because I will lose my history of previous commands. If I'm using modules:methods with long names this takes a lot of typing time for each change made.
Is there any method to reload the .beam files in the current directory while in an Erlang terminal? Or is there any way to load the previous command history of the Erlang terminal?
You can use the l(Module). command in the shell which loads, or reloads, a module from the current directory into Erlang.
I would suggest something like active or sync but straightforward approach with c/1, l/1 and nl/1 works too
[edited]
Run your application from eclipse and check the node name, the default is #. Shut that down.
Start a separate erlang node with the same name. Now when running the application from eclipse that node will get used and you can use the shell in the terminal, while erlide will be able to reload beam code automatically when saving files.