How to clear node.js terminal in Cent OS 7 - node.js

I'm using Node.js in VScode. Say my run command is node index.js. As I run command various console.log statements print during course now I want to clear console log without stopping current node process. In existing case To clear the console I have to stop the running process using Ctrl+c. use clear command in terminal to clear screen and again run the process using node index.js. My question is there any method by using which i can clear terminal window without stopping current node process.

You can use console.clear() function in your node program. If you want to clear vscode terminal window, just click by right mouse on terminal and select Clear (shortcut Ctrl + K)

Related

How do I keep my discord bot online even with my terminal closed

I have a pretty simple discord.js bot and would like to keep it running even when I close my terminal and/or my computer.
I have already tried pm2 and just keeping my terminal open throughout the day, but it wastes battery.
I keep running pm2 run NAMEOFFILE.JS in the right folder, but it already says I'm running the file.
You must use a process manager, like pm2 (pm2 start yourfile.js) or forever (forever start yourfile.js). You can install them with npm (npm i -g pm2, npm i -g forever).
EDIT: Yeah use PM2 or some other application, screen is a bad idea.
If you're on either MacOS or Linux, you can use the screen command (Or cygwin on Windows). It basically creates another terminal. To use it you can do screen -R <name>.
When you use the -R <name> (capital) the computer will look for a screen with the name and reattach to it. If it can't find a screen with that name it will create a new screen with that name.
So for you, you might do screen -R Discord. After you attach to the screen you can do whatever you want as if it were a terminal. When you're done, you can press ctrl+a then d to detach from the screen, then you can close the terminal window.
https://ss64.com/osx/screen.html

running node js app in background in ubuntu

I have a nodejs compiled application that I run from a terminal window on my ubuntu vps.Is there a way to run it in the background, meaning i can afford to close my terminal window and it still works. Note this exe prints the messages on the terminal window when its running
tried PM2, it errors out saying "awaiting restart"
tried nohup, it does not error out and shows process has started but exe does not what it shall do, meaning its not working.
if i do ./app , it works but then i can not close the terminal window.
used tmux, loving it so far.
think might use PM2 with tmux where i can.

What can I do to make node/npm/related commands send their output back to the terminal I used to launch them?

What can I do to make node/npm/related commands send their output back to the terminal I used to launch them?
I've recently installed NodeJS 10.4.2 on Windows 10. When I run any node or npm command from PowerShell, Git Bash, or the Node terminal shortcut, a new window is opened, the output is directed there, and the window is closed. I feel like there must be a setting I've flipped under a previous installation, but I can't find it, and it's making me bananas.

Node wrapper to start a terminal application like vim, emacs, tmux

TLDR; how can I run a node process from the terminal, start a process from node, exit the node process and have the process be attached to the parent terminal?
I am writing a node terminal application which should end by starting a new terminal application (e.g. vim, emacs, tmux). I want this application to run as if is was executed manually in the terminal that started the node application.
My current workaround for tmux is to run the node application, which sets up a new tmux session and echoes a tmux attach-session command just before the application exists. The user can then type this command manually in the terminal and execute it. Now the tmux session runs attached to the terminal.
I would want to move the attach command into the node application, but have the same end results. I.e. the node application terminates and the tmux session runs attached to the terminal. This seems to me to be required to do the same for applications like emacs, vim, etc. Where I cannot decouple the setup and attach. (For all I know vim and emacs can handle this decoupling, and I would be interested in knowing, but the original question asks for a general solution for any terminal application).
By attached, I mean as if the command/program was executed manually in the terminal.
The POSIX exec solves this problem as #Amadan has commented above. This solution does not work on windows.
The following snippet shows an example of how to do this with the kexec module.
const kexec = require("kexec");
kexec("emacs -nw");

Run a program in a different thread from OSX command line?

I'm developing a node.js server application. To speed up the process, I've configured my editor so it will run the current file with the command node <current_file> when I press a key. The problem is: the editor blocks when the file starts a server. How can I change that command so it runs node.js on background?
You can start it asynchronously by adding an & at the end:
node <current_file> &

Resources