Skip to content

Working with Browser (Clientside) JavaScript in NTVS

Steve Lee edited this page Jun 21, 2015 · 5 revisions

IntelliSense and Editing

Difference between Browser-land and Node.js-land Code

There are slight differences between browser-side JavaScript and Node.js. The biggest difference you'll notice is global objects and global scope.

In browser-land, the window object and all of it's properties, methods, and events are part of the global scope. This means that wherever you are, identifiers such as 'window', 'document', 'onclose', etc. will be available to you.

In Node-land, there are different global objects (such as 'global', 'process', etc.), as defined in the Node.js documentation.

Customizing Browser and Node.js IntelliSense modes

By default NTVS will only display completions for Node.js-land JavaScript, not for browser-land JavaScript. You can modify these settings as follows:

  1. Right click the file in Solution Explorer, and selecting Properties.
  2. Change the Build Action to:
  • Content for Browser-side completions
  • Compile for Node.js-land completions
  1. Close and re-open the editor tab associated with the file if it was already open

Customizing Browser and Node.js Editing/Formatting Options

Node.js-land code and Browser-land code use different formatting options.

  • Browser-land options are available in Tools -> Options -> Text Editor -> JavaScript
  • Node.js-land options are avaialble in Tools -> Options -> Text Editor -> Node.js

Debugging

NTVS is designed to debug Node.js code only. For client-side code debugging, you can use your browser F12 debug tools You can also use the built-in Visual Studio JavaScript debugger that works with Internet Explorer. Unlike ASP.NET projects, we don't have automatic attach to IE when launching a web project (this is feature request). But you can still do Debug -> Attach to Process, select iexplore.exe, and make sure that you're using the Script code type, to get the same effect.

Clone this wiki locally