I'm aware that this can be done manually from the terminal using:
echo -n -e "\033]0;My terminal tab title\007"
I tried putting this into a console.log
and process.stdout.write
and fiddling with the escaping, but I can't get it to work.
Advertisements. REPL stands for Read Eval Print Loop and it represents a computer environment like a Windows console or Unix/Linux shell where a command is entered and the system responds with an output in an interactive mode. Node.js or Node comes bundled with a REPL environment.
js/JavaScript code. To launch the REPL (Node shell), open command prompt (in Windows) or terminal (in Mac or UNIX/Linux) and type node as shown below. It will change the prompt to > in Windows and MAC. You can now test pretty much any Node.
var _message="Hello World"; console. log(_message); Like any other programming language, in nodejs we have single line comment using double slash like // and multiline comments using single slash with star like /* */ .
To save anyone reading this a bit of time, here is a function that will do it in strict mode:
function setTerminalTitle(title)
{
process.stdout.write(
String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7)
);
}
There is node library for that: node-bash-title
To install the library:
npm install node-bash-title --save
And within your script:
const setTitle = require('node-bash-title');
setTitle('🍻 Server');
This package also provides an executable script. You can use that in your npm scripts. For example:
"scripts": {
"start:dev": "set-bash-title server && node server/app.js"
"start:prod": "node server/app.js"
},
So you can remove the title script from your code. Furthermore, the title is only set if you want to set a title(in development mode). In production mode you may not want to set a title as your script may not be executed in a XTerm :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With