Node.js on Azure via Visual Studio and Git

I was just messing around with Node.js Tools for Visual Studio and Azure and ran into a few gotchas while getting everything setup. Hopefully this helps you get going.

1. Install the Node.js Tools for Visual Studio

2. Create a new “Basic Express Application”

  • Uncheck “Create directory for solution” – This will put the sln file in the same dir as the project file. If you don’t uncheck this then the “git sync” will push the website into a subfolder in Azure. Unchecking will put the site in the root, which where you want it.
  • Check add to source control. This is so you are prompted to add a local git repo.

3. Click “Yes” to run npm install.

4. Choose “Git”

5. Hit F5 to ensure that the project runs. You should see this:

6. Back to VS, Team Explorer, Changes. Enter a commit message and click Commit

7. Go to the Azure web portal, Create a new site

8. Go to the Dashboard of that site and click “Set up deployment from source control” in the right rail and choose Local Git Repository

9. Copy your Git url

10. Back in VS, Go to Team Explorer, Unsynced Commits and enter the URL of your Azure website git repo and hit publish. It will prompt you for creds. Enter your FTP user creds for that site, not your Azure account creds.

You will see it deploying on the Azure portal

11. Hit your site URL. You might get this error.

I went into the FTP of the site and found the log file "Logging-errors.txt

Which had this error:

Wed Aug 13 2014 22:35:53 GMT+0000 (Coordinated Universal Time): Unaught exception: Error: Cannot find module 'debug'
     at Function.Module._resolveFilename (module.js:338:15)
     at Function.Module._load (module.js:280:25)
     at Module.require (module.js:364:17)
     at require (module.js:380:17)
     at Object.<anonymous> (D:\home\site\wwwroot\node_modules\stylus\lib\visitor\evaluator.js:21:13)
     at Module._compile (module.js:456:26)
     at Object.Module._extensions..js (module.js:474:10)
     at Module.load (module.js:356:32)
     at Function.Module._load (module.js:312:12)
     at Module.require (module.js:364:17)

which means that npm didn’t install the “debug” module which is a dependency of “stylus”. I think the problem is related to this: http://stackoverflow.com/questions/18401606/npm-doesnt-install-module-dependencies. So, I added “debug” to my package.json file.

"dependencies": {
     "express": "3.4.4",
     "jade": "",
     "stylus": "",
     "debug":  "*"
   }

Committed those changes and sync’d.

And now the site works