How do I reactivate terminal in VS Code? - javascript

I am very new to coding and following a tutorial at the moment (building a simple CRUD app). The issue is that once I run the command "nodemon app", I can no longer use any other commands. I can type it out but hitting enter does nothing. How do I use other commands without opening a new terminal?
click here for image

Ctrl+C will interrupt the running process in a terminal, in this case, killing nodemon.
That would allow you to run other commands, but will lose you your nodemon process.
Another option (that might be more suitable for VSCode) is to open a second terminal (Ctrl+Shift+`, or Ctrl+Shift+5 to open side-by-side). In the second terminal, you can then execute whatever other commands you want.
Alternatively, you can append the & character to a command to have it run in the background. This would allow you to run something like nodemon app & and then run other commands, but be aware that in this arrangement, the output of the commands will become interleaved - so if the node application is writing to the console and the other command also outputs information, they might become tricky to read.

Related

Changes to minio browser do not appear when running minio server

My goal is to modify the Minio browser for front end appearance in house. I'd like to add features too but can't seem to get either to work and feel like I'm missing something about how go accesses npm or the browser.
I have made changes to the Minio web browser (javascript) and can see them when running with npm (in ./browser 'npm run release;npm run dev'), but when I try to run minio server built with the same git clone (changes is browser subdir) and browse to localhost:9000 I don't see any of the changes.
It would also be nice to run the browser with npm and connect to the running server "./minio server ~/data", but they don't seem to talk and I'm unclear on how they're connected.
This seems to be a simple case of all the things I tried and in the right order.
Correct order:
cd browser; npm run release
cd ..; make
./minio server ~/minio-data
It seems I'd tried all of these separately but not in the obvious order. I'm assuming npm makes the ui-assets.go which gets included by the make

How to run multiple js servers

I'm developing a discord bot for discord at the moment, and to run the bot, I have a few different files. I've run into some problems along the way that all ended up having the same fix, or at least the only fix that I could come up with. That fix would be, instead of running them in my main file (index.js), I could just run 3 separate batch files using nodemon (https://www.npmjs.com/package/nodemon). I currently have 3 batch files to do so. Those batch files look like this:
nodemon index.js
pause
This would be for the main file.
nodemon logs.js
pause
This would be for the file that logs messages.
nodemon welcome and goodbye.js
pause
And this would be for the welcome and goodbye logs.
The only issue is, is that it clutters up my desktop with 3 different prompts, making it confusing as to what does what. I was wondering if it'd be possible with nodemon (or any other npm like this) for me to run all 3 of those batch files in one single command prompt.
And of course I'm open to other npms, but if I'd have to use another one, please include a way for it to automatically restart the server when I save the file in it as well (if possible). Since that's the main reason I like nodemon. I'd also like to be able to use a command prompt/batch file rather than the Visual Studio Code terminal.
If you're wondering what I mean when I say, "...automatically restart the server when I save the file," . (https://imgur.com/a/rw2Qagp if it doesn't show, don't know how to format this stuff)
Whenever I save my code in Visual Studio it will restart and load the new code.
I'm still a little new to coding and stuff like that, so if my terminology is off I do apologize. If I did use a term incorrectly and you are confused/have a question about it, leave a comment and I will do my best too explain what I mean.
Thank you for taking time to read this.
You can use concurrently or parallel in order to make it cross platform
example with concurrently:
package.json
{
"scripts": {
"serve": "nodemon index.js",
"logs": "nodemon logs.js",
"start": "concurrently \"npm:serve\" \"npm:logs\""
},
"devDependencies": {
"concurrently": "^5.0.0",
}
}
Edit: you may want to take a look at the VSCode Compound tasks
Here's an example setup
Welcome :-)
I think you mean bash file (.sh) instead of batch file. So, in the terminal, you can && commands to chain them together.
For example, you could chain them together like this:
nodemon ./appOne/index.js && nodemon ./appTwo/index.js && nodemon welcome and goodbye.js
and they will all execute at one time. Additionally, you could make a bash file somewhere on your computer that did exactly what I typed above :-)
Now if you wanted them to go to the background and you wanted to forget about them, you could put them in the background with one ampersand... like so:
nodemon index.js &
and it would disappear and you'd have your console back. It would also print out a process ID (PID) of what that node process is under, so you can find it and kill it later (via kill -9 processid)

VScode extension clean diagnostic collection on second run

I am creating a diagnosticCollection on a vscode extension following this
sample:
It works but if I run the same command twice on the same file it creates a "duplicate" diagnostics issues list in the problems terminal window.
What is the best way to clear that terminal window problems? I have tried to run collections.clear() which I thought would do the job but it did not work.

Run Windows Node.js script in background when the user logins by setting a Run key

I'm running on Windows Server 2012R2.
I have a node.js script which I want to run when the user performs logins.
To do this I'm setting the command to run in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry path.
I set this command:
/path/to/node/node /path/to/node/script args
This works fine, but it will spawn a terminal showing the command output, while I'd like to run this command in background and detached from any command terminal.
I tried to replace the previous command with:
start /b /path/to/node/node /path/to/node/script args
but in this case there is no evidence that the script was even started.
I also tried to wrap the following command in a .bat script:
start \b node script args
set the name of the script in the Run key: in this case I can see terminal flash but then the script is not running anymore (I suppose that the script is executed but then it is stopped as soon as the parent process is terminated).
I want to avoid to convert the script in a windows service, as long as a simpler solution is possible.
A solution not using the Run registry key is also fine, as long as it fulfils my requirement (run a script in background when the user logins).
Actually it's pretty easy , use forever.js module
after installing the module use
"forever start main.js"
It will start running as your background process

"..." in every action in node.js

First I want to clarify that I'm new in node.js and I'm not a linux user, so the cmd isn't my thing.
Every time I try to do something, for example
sudo npm install express#2.6.5 (as it's in a sitepoint ebook example)
or
node example.js (as another tutorial)
Every time, the response is a "..." in the screen (http://www.screencast.com/t/dx6VZhsVtl), so my 3 questions:
Why this happens (I'm missing some configuration or something)?
How to install packages (as the ... is always the response)
When I run a program, I don't have to specify the absolute path, just the file?
It looks like you're trying to run the file example.js, but you're still running a node REPL session (indicated by the >, see the link for more details). Press Control+C a few times to exit to get back to regular terminal (it should show something like username#machineName:).
To run a node file, use node [filename].
To open a node REPL session, simply use node.

Categories

Resources