webpack command of npm run dev from a new line - javascript

After finished specified command npm run dev, I can't again write new command in node console.
How can I continue to write from a new line?
Thanks, everybody for the help!

npm run dev in most cases is intended to keep running, detect changes, re-transpile files and (hot) reload the application. That's intended behavior, so don't panic.
You should leave that terminal untouched and simply open a second one if you want to do anything else.

You will have to open another terminal window. The reason is that webpack is now listening for changes - meaning the process in your current terminal window is still running.
Opening another terminal window will allow you to run other commands while the webpack process is still running.

I found the right way. CTRL+C, after need to choose stop or not the execution of processing of listening and then will get a new line.

Related

How to get output of the JS file using VS Code

When I run the code, nothing shows in "Output" tab. I installed nodejs as well as Code runner extension. How to fix this issue?
enter image description here
I want to get the output of my code.
Install Node.js from https://nodejs.org.
open VS Code.
from the file tab at the top, choose open folder.
navigate to your working directory where your project is open.
from the terminal tab at the top, choose new terminal.
in the terminal, write the following command:
node sample_1.js
replace the sample_1.js with your file name
This is the top menu
and this is the terminal:
--
and you don't need a code runner extension, every time you want to run your JavaScript code, write the command
node YOUR_FILE_NAME.js
Otherwise, if you want something to automatically detect the changes you make to your file and automatically run the code when you save the file, you'll need a package like nodemon.
to install nodemon, in the same working directory, open up the terminal and write the following commands:
npm init -y
and then:
npx nodemon sample_1.js
replace the sample_1.js with your file name
Nodemon will keep running in the background and every change you make to any of your files in your working directory will make nodemon reload, and you'll see the changes in the terminal immediately.
I fixed that issue. I installed JavaScript Debugger(Nightly). After that now OUTPUT tab shows output of the js file.
https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug-nightly

Open new terminal in MacOSX and run node script

I have been trying to figure out how to open a new terminal window from a Node application and run a preset command or script there.
I can open the terminal window:
const { exec } = require('child_process')
exec('open -a Terminal ' + process.env.HOME)
And this works fine, I have done a bit of research but it seems I can only find examples directed to bash
Could anyone help me on this?
Thanks
One way to do this would be to place the commands you want to run in a shell script with the .command extension. By default, these files will be opened in the Terminal application on macOS. This is a bit of a workaround, but I think it achieves what you would like to do.
Say we have the file hello.js containing the following:
console.log("Hello World")
And the shell script run_node.command
#!/bin/bash
node hello.js
Running the command open run_node.command will open a new Terminal.app instance and run the shell script, which in turn runs the node command. The terminal will close when the script exits.

How to open non integrated terminal window from vscode extension?

I am developing an extension for Visual Studio Code. I need to open a terminal window and run some command there (One after another finishes). Same as Terminal.sendText but not in integrated terminal. Is there a way to do that?
Update
The closest I've got is using:
const childProcess = spawn('node', ['--version'],{
shell: true,
detached: true,
windowsHide: false
});
And the problem is it closes automatically
You could possibly run the machine's terminal application and specify a command to run, like with mate-terminal, -e option. You could then run bash with certain startup commands How to invoke bash, run commands inside the new shell, and then give control back to user?

Issue related to running of New React App

I installed Nodejs(v 10.16.0 LTS) and then using Windows Powershell I run following commands
npx create-react-app my-app
cd my-app
npm start
The actual problem I am facing is that if PowerShell window is opened in the background, then my code works properly. But when I close PowerShell and reload Browser Tab, the error occurs which say
This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall.
Kindly help me to figure out this issue. Thanks
When you close PowerShell window you terminate your React app as well, it has to stay opened. Running npm start kicks off local server with your app running. If you want to have possibility to have application running with terminal closed you can use libs like https://www.npmjs.com/package/forever, but I do not recommend that- it's easy to forget you have one app instance running already :)
When you run the command npm start, this is the expected behaviour. This command spawns a new npm instance in the directory from where you have executed it and directs it to start a server. The catch here is that the server runs as an attached process with PowerShell, by default and it is bound to terminate once you close the PowerShell window.
To manually detach a process from the terminal, we use an & after the command on a UNIX-based system (Linux, MacOS etc.) something like npm start &.In case of PowerShell, you can make use of a built-in function called Start-Process like this -
Start-Process -NoNewWindow npm start
If you'd like to read more about it, you can refer a blog post here - https://ariefbayu.xyz/run-background-command-in-powershell-8ea86436684e

Node compile on file change

I'm doing small programming challenges locally.
In one tab I draft a solution, let's call it challenge.js and in another tab I run the command node challenge.js whenever I make a change.
Is there a way for node to compile automatically whenever a change has been made to challenge.js?
The first comment answered the question.
I installed nodemon:
$ npm install nodemon -g
$ nodemon app.js
and it works perfectly.
This is for development environment?
If yes, you can use a build tool like webpack, gulp, etc.
Webpack provides a tool webpack-dev-server, that recompile your bundle at every change.
I hope to have helped.
Use nodemon. https://www.npmjs.com/package/nodemon I work in server development and it refershes the server every time I save a file. If its a case you want something live to restart every time it crashes or if theres any change use pm2
https://www.npmjs.com/package/pm2

Categories

Resources