Evaldas Buinauskas
Evaldas Buinauskas

Reputation: 14077

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.

Upvotes: 5

Views: 3083

Answers (1)

Alexander Troshchenko
Alexander Troshchenko

Reputation: 330

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.

Upvotes: 6

Related Questions