This is the easiest one to implement, and it’s the fastest way to litter your clean code with extra lines of info - but it can also (sometimes) help you find and fix the error. In Java, it’s () in Python, it’s print(), you get the idea. It’s built in to Node.js and prints in the terminal just like it’s built into JavaScript and prints in the browser’s console. Console.log() - the tried and true standby, this one really needs no further explanation if you’ve ever written a line of JavaScript.There’s a number of ways to debug your misbehaving Node.js program, I’ve listed them out below with links to learn more if you so desire. Let’s go over the options and then I’ll show you the easiest way I’ve come across in my own development. You just can’t, and it stinks.īut it is possible to debug, it just takes a little more elbow grease. Unlike JavaScript in the browser, or Java with a powerful IDE like IntelliJ, you can’t just set breakpoints everywhere, refresh the page or restart the compiler and slowly walk through the code examining objects, evaluating functions and finding the mutation or missing variable, etc. node-supervisor.If you’ve ever had the pleasure of writing code for a Node.js project, you know what I’m talking about when I say debugging it to figure out what’s going wrong isn’t the easiest thing. The same trick might have to be used with some of the tools similar to nodemon, e.g. Using these settings, nodemon works fine when run from a WebStorm Run Configuration. The fix for this is to specify the location to the node executable using the -exec /usr/local/bin/node parameter. The error seems to be caused by WebStorm not seeing the node executable on its path. The -exec part is important, as the execution will fail with the following error: /usr/local/bin/node /usr/local/bin/nodemon server.jsĤ Oct 13:56:50 - to restart at any time, enter `rs`Ĥ Oct 13:56:50 - watching: /Users/foo/testĤ Oct 13:56:50 - starting `node server.js`Ĥ Oct 13:56:50 - exception in nodemon killing nodeĪt errnoException (child_process.js:980:11)Īt Process.ChildProcess._handle.onexit (child_process.js:771:34) This will instruct the node interpreter to execute the nodemon script using the following command line: node /usr/local/bin/nodemon -exec /usr/local/bin/node server.js. Node parameters: /usr/local/bin/nodemon -exec /usr/local/bin/node.Then, in your WebStorm Run Configuration, add the following, leaving everything else unchanged: This will install nodemon globally on your machine. To install nodemon, use the following (if required, use sudo to run the installation with root privileges: npm install -g nodemon You should save the debug/run config to file so your teammates can also easily debug/run your nodejs app like you Then from Webstorm 's run/debug config, set Node parameters to be :path_to_project_dir/node_modules/.bin/nodemon You may NOT have nodemon exists from which nodemon command, then you should have it in your package.json ie nodemon be installed at :project_dir/node_modules/.bin/nodemon usr/local/bin/nodemon) under "Node Clark, thanks for confirming. It looks like the workaround with -exec isn't necessary anymore, at least when using the newest version of nodemon and Webstorm 7 or 8.Īll you have to do is specify your path to nodemon by obtaining its path with running which nodemon in your console (e.g.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |