I have installed "Enide Studio 2014" on Windows 7. Then I created an "Node.js Express Project". Everything went smoothly, a new project was created. I was able to run it without any problems.
As stopping and starting node server everytime I make any changes in the code takes unnecessary efort while developing, I wanted eclipse to "monitor" changes and restart node accordingly. As nodeclipse provides an option for this purpose, I tried to configure forever as node monitor.
In Nodeclipse preferences Node Path was set as "D:\Software\Development\NodeJS\node.exe" as it should be. Forever was installed in "D:\Software\Development\NodeJS\node_modules\forever\bin\forever" so I set "Node monitor path" in as that.
After this I was not able to run the project again.
When I check console output, the command issued (and failed) was:
node D:\Software\Development\NodeJS\node_modules\forever\bin\forever D:\calismaalani\nodejs\deneme\app.js
I copied the command line and issued it on the command window myself and got:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
error: Cannot start forever
error: script D:\Software\Development\NodeJS\D:\calismaalani\nodejs\deneme\app.js does not exist.
As it is clearly seen, Nodeclipse was trying to add node_home path to the absolute path for my app. I have tried to set some environment variables but could not manage to get the right path for my app.
What is wrong here? How can I fix this?
Since Nodeclipse 0.17 Run with Node monitor is hidden as it raised more questions then solved.
Please launch via CLI as forever and TCF-Terminal is nice shell integration into Eclipse,
so you can have several forever instances running for different project in separate tabs.
You can specify the "Node options" path in Nodeclipse preferences as D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir . and Nodeclipse should automatically use forever to start your node Js application.
I use nodeclipse version 1.0.2.x and use nodemon to monitor the application and it works fine for me.
Edit:
In your case, you cannot pass the absolute path to forever . if you need to ,you can use the "--sourceDir . " option of forever. The --sourceDir and the "." option looks for the full path of the application. So your command will look as follows:
node D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir . D:\calismaalani\nodejs\deneme\app.js
You need to give Node monitor path as D:\Software\Development\NodeJS\node_modules\forever\bin\forever --sourceDir .
Incase you are using nodemon, you need to give the path as C:\Users\ashwin_valento\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js --watch
Related
I added in package.json this into scripts:
"debug": "NODE_PATH=src nodemon --exec babel-node src/run.js --inspect",
It is pretending that it is debugging but jumping on selected lines how it pleases. I'm not that "expert" in JavaScript (I'm Java) but really this is pain in ass.
How can I debug backend without debug? Srry I'm angry because this is second time I'm giving change to JavaScript and this is second time I'm furious about this stupidity.
Thanks for any hints.
P.S.: if there is better software, tool to debug please just refer to it
In WebStorm, the easiest way to debug the application started via NPM stript is using the icon in the gutter: open your package.json in editor, right-click the icon to the left of your script and choose debug:
See also https://blog.jetbrains.com/webstorm/2017/09/debugging-node-js-apps-in-webstorm/
Note that:
babel-node is deprecated and not recommended for using in production. To get ES6 code compiled on-the-fly, try running node with -r #babel/register. see https://babeljs.io/docs/en/babel-register
by running nodemon --exec babel-node src/run.js --inspect, you pass --inspect to your application, not to node interpreter, so this command doesn't start the debugger. Node options have to be specified before the javascript file, otherwise the passed options will be treated as application arguments, not as node.js args
Right now, VSCode(Visual Studio Code) is considered as best tool for development, which is light weight and user friendly.
You can get different extensions based on your requirement.
To debug node js in vscode, go to debug window -> add configuration -> type attach process -> press ctrl + space -> press enter on attach suggestion.
After that, run command, node "your file name" --inspect
Press F5, your debugger will be attached
Node js debugging using VSCode
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.
I'm familiar with debugging my own node apps (usually with node-inspector). Today I'd like to debug someone else's program. I'm trying to track down an issue with supervisor. So naturally I just add a --debug (or debug-brk) to the command call, but it passes that to the code that it is supervising.
I've tried adding debugger lines to the js file for supervisor but that didn't work (probably because no debugger was attached at that time). There's a bit of a race here -- I need to start the debugger and attach it to the supervisor process after it starts but before it processes its arguments from the command line.
What I really want to do here is stop supervisor and debug it before it processes its command line arguments. How can I do this?
I had the same problem while developing my hexo blog. The documentation isn't all that complete yet so I find myself needing to reverse engineer at times.
The basic idea is that in Node.js even your cli apps are simply normal node apps that you are exposing to the OS command line interface. On Unix systems you are using this line:
#!/usr/bin/env node
To allow the environment to execute the script.
Many cli based node apps try to insist that you install them globally with the -g option.
npm install -g node-inspector
I personally prefer to have as much control of my development environment as I can get, so I prefer to break some conventions and check my node_modules in to source control along with installing everything I can locally by dropping the -g.
npm install node-inspector
Now you don't have to do this in order to make this work, I'm just describing this setup because it relates to your question. When I run node-inspector I can't simply use:
node-inspector
Instead I must explicitly invoke it from within my project. I do this by executing the symlink in my node_modules/.bin folder:
node_modules/.bin/node-inspector
Now I'm running node-inspector just like you.
Next all I need to do is start the cli process in debug and optionally pass params to it:
node --debug-brk node_modules/.bin/hexo generate
Note I am explicitly calling the symlink here and not simply:
node --debug-brk hexo generate
If I tried the line above I would get an error: "Error: Cannot find module".
I hope this helps.
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/
Node.js and the express generator are really handy and simple to understand. I cannot however get my server to start by running c:\my-application-root>DEBUG=my-application ./bin/www
Windows doesn’t seem to understand that command. I can however run it by calling node ./bin/www
Am i missing something?
Did you try set DEBUG=my-application followed by node ./bin/www? Windows does not allow setting an environment variable in the way that Linux and others do.
1st command 'set DEBUG=my-application'.2nd command 'npm start'
First you need to go the cmd that is supported by node (search for node cmd when you click in windows icon if you're using windows 7)
type
set DEBUG=my-application
Second
simply cd c:\my-application\bin\
Then type
node www
www is the file that contains the script needed by node to run your server, DEBUG if set as an environment variable will also help you run node against it since the path will be known