-
Notifications
You must be signed in to change notification settings - Fork 355
Working with Browser (Clientside) JavaScript in NTVS
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.
By default NTVS will only display completions for Node.js-land JavaScript, not for browser-land JavaScript. You can modify these settings as follows:
- Right click the file in Solution Explorer, and selecting Properties.
- Change the Build Action to:
- Content for Browser-side completions
- Compile for Node.js-land completions
- Close and re-open the editor tab associated with the file if it was already open
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
NTVS is designed to debug Node.js code only. For client-side code debugging, you can 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.