Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does someone debug Sails.js code in Visual Studio?

I'm currently trying out Node.JS and using Visual Studio Community with Node.js Tools as my primary IDE.

If I would create an Express application using this interface: enter image description here

Then I would hit F5, my Express application would start and I'd see this nice debug window:

enter image description here

However, if I install Sails.js using npm -g install sails, I no longer see this debug window in my test Sail.js app (if I create one in my Visual Studio), nor in Express app.

My application would start as expected, except that I can't see debug window anymore.

Debug window comes back only if I do following:

  1. Remove Sails from my machine using npm -g uninstall sails
  2. Reinstall node.js

How do I get debug window if I have Sails installed? I'd like to have it for both Express and Sails applications.

like image 562
Evaldas Buinauskas Avatar asked Jan 19 '16 19:01

Evaldas Buinauskas


People also ask

How do I debug sails app?

Attach the Node debugger and lift the Sails app (similar to running node --inspect app. js ). You can then use a tool like Chrome DevTools to interactively debug your apps (see the Node Inspector docs for more information).

How do I debug HTML and JavaScript code in Visual Studio?

The simplest way to debug a webpage is through the Debug: Open Link command found in the Command Palette (Ctrl+Shift+P). When you run this command, you'll be prompted for a URL to open, and the debugger will be attached. If your default browser is Edge, VS Code will use it to open the page.


1 Answers

Ran into a similar issue of running Sails application inside Visual Studio. Here's how I got my project properly running in Visual Studio, in case any stumbles on that question.

  1. Create Create Blank Node.JS Console Application in the VS
  2. In another folder outside of your project initialize your sails app (if you haven't already), e.g. sails create appName. If you already know your API controllers/models, it's a good idea to create them right now. If not, you'll have to do it manually rather than using sails generate api

  3. IMPORTANT: In Sails project folder, remove node_modules, in my case existing node modules were throwing VS npm off the track

  4. In the visual studio, right click on your project, go to Add > Add Existing Folder...
  5. Select your folder with Sails Application
  6. Once it's imported, you'll notice that you have a folder with sails application that also has app.js. Select all the contents of sails project and move them a level up to your root. It should replace app.js, package.json & readme.
  7. Right click on npm, select Install missing packages...
  8. After that, right click on you app.js file and select it as start js file
  9. Run/Debug the application. It should work just fine.

Hope it helps.

like image 51
Alexander Troshchenko Avatar answered Oct 31 '22 20:10

Alexander Troshchenko