How do you set up file watcher in Webstorm to restart Node.js? - node.js

What I am trying to achieve is to trigger same behavior as Menu option Run > Run 'server.js'

Please try using Live Edit here - see http://blog.jetbrains.com/webstorm/2014/08/live-edit-updates-in-webstorm-9/. It allows re-starting node.js application on changing the code

You need to integrate webstorm with nodemon instead of the main node program. Basically nodemon is in charge of restarting your application and not webstorm.

Related

Vue JS Intellij setup

I am working on a Vue js application but am having difficulty getting it to run/debug within IntelliJ. I am currently running it from the command line but I'm interested in getting it to debug in IntelliJ. Not many tutorials out here on getting this set up to work. Is there anyone that has experience in setting up this framework and IDE?
Steps are rather straightforward and described in blogpost:
First, install the JetBrains IDE Support Chrome extension. This will bind the browser debugger environment with IntelliJ in real-time.
start the server with npm serve (can be done from a gutter in package.json):
create a new JavaScript debug configuration, specify the URL your app is running on (usually http://localhost:8080) in it, put the breakpoints right in the source code, and start the debug session.
See also https://blog.jetbrains.com/webstorm/2019/03/get-started-building-apps-with-vue-js-in-webstorm/ for some hints on working with Vue.js in IDEA. And https://medium.com/dailyjs/stop-painful-javascript-debug-and-embrace-intellij-with-source-map-6fe68eda8555
You can add "Run Configuration" for any project to run in Intellij. For this, you must have a run script in package.json.
Refer below link for a screenshot. NPM Run Configuration Sample:
Choose NPM and give like this. Once done, you are all ready for clicking the RUN button available in the toolbar to run the project

Why server restart is needed in Node.Js for every change?

I am very new in Node.Js. I just started node.js basic tutorial. But when I change my code I have to restart the server all the times. But is there any way where no need to restart the server again and again.
Nodemon is the best solution for this.
Install nodemon like this "npm i nodemon"
Then restart your project with nodemon, "nodemon app"
You are good to go...
You can install node-supervisor to restart automatically your server when you change the code.
I'm not sure on the details of the compilation process. But I think it's correct to say that on app start, your source code is parsed into computer instructions represented in memory and executed. During runtime source code files are not re-parsed. And so changing the source code will have no effect on the running application. Unless the application re-parses a file prior to execution of the code in that file. Possibly a service worker... But I'm not sure and that would be an exception.
A good way of thinking of nodejs and javascript files (imo) is that the javascript files are configuration for nodejs. Which is a c++ app. So if the configuration changes you need to restart node to read the new configuration.
There are tools such as nodemon that will monitor the source code for file saves and trigger the node application to restart.
Check out Nodemon.
nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.
nodemon does not require any changes to your code or method of development. nodemon simply wraps your node application and keeps an eye on any files that have changed. Remember that nodemon is a replacement wrapper for node, think of it as replacing the word "node" on the command line when you run your script.

Debugging node app in WebStorm when run from gulp

I am using webstorm 10.0.2 and have used the bangular yeoman template to generate a project. I can run the gulp commands via the gulp window, and I can set a breakpoint in the gulpfile.js and it will hit it, but I can't seem to get it to hit a breakpoint in my server.js
It looks to me like the gulp file is launching another instance of node and thus when you do "debug" from webstorm you are just debugging the gulp.
I also tried with another project using yo hottowel but get the same thing - I am unable to debug the actual application through webstorm.
Can anybody tell me how to configure webstorm so that I can debug the actual server side node code but still use the gulp build tool?
I contacted JetBrains support back in May 2015 and their response was:
It seems this cannot be done quickly. In short, the problem is that serve-dev task starts new process (nodemon) that takes app.js
There is no workaround how to debug such spawned processes right now. We would really appreciate if you'll submit a feature request about it in our YouTrack: https://youtrack.jetbrains.com/issues/WEB
The only way you can try to avoid it - try to create a separate task that will run app.js directly without nodemon process and debug this task instead.
It seems the best option is to use https://www.npmjs.com/package/gulp-node-inspector

Rerun node app on WebStorm after code change

I recently started to use WebStorm and before this I used to use nodemon as a supervisor, so it watches any code change and restart the server.
How can I reach the same effect running node by the IDE?
Thanks!
[EDIT]
While there's no 9 version/live edit I'm posting my solution:
It's just have nodemon installed globaly and used it as a Node Parameter in the project configuration.
More details and screenshot below:
Discover where is the nodemon's path;
Here (OSX) is "/usr/local/bin/nodemon" and it could be discovered using "which nodemon" (on terminal);
Use this path in the Node Parameter field;
Go to Run > Edit configurations, choose your configuration below the Node.js option at left;
Screen shot for detail:
https://photos-4.dropbox.com/t/1/AAC1WJBhh1RUnIBZEaG3YQ80iMswJH2XmFqb4GtiYwqj2A/12/11986044/png/1024x768/3/1413997200/0/2/Captura%20de%20tela%202014-10-22%2013.52.47.png/exYBAGzU3uZwj45i3XxZkgPKb_mfyL_O_q3EFRK5pFk
Possible since WebStorm 9 - see http://blog.jetbrains.com/webstorm/2014/08/live-edit-updates-in-webstorm-9/

How to edit and deploy code without restarting server?

I have node server which i run using forever. But each time if I edit my code I'll have to restart the server. I came across the module called hotnode which can perform live edits but will it have the same performance as the forever module or can I run my code using both the modules. I am confused. Any help wil be much helpful
Have a look at nodemon.
nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application.
As an alternative to nodemon you can use node-supervisor.
I used to use nodemon, but for some reason it didn't detect code changes on my linux box, which supervisor did flawlessly.
The downside is that it doesn't (or at least didn't) give the colorful output nodemon gives.

Resources