Node.js meets Visual Studio
3rd-party modules do not yet work; I will use module-deps to find and reference them.
This project has been abandoned..
Instead, use the Node.js Tools for Visual Studio
First, install Node.js and npm. NodeSense will generate IntelliSense for the built-in modules from the version of Node.js used to run it.
Next, install NodeSense system-wide from an administrative command prompt:
npm install -g vs-nodesense
Finally, open a command prompt in your project folder and run NodeSense to generate IntelliSense files:
This will generate files in
node_modules/.vs-nodesense, including a copy of Node.js' built-in modules, links to every JS file in your project, and glue code to make it all work together in Visual Studio's IntelliSense engine.
Make sure this folder is in your
.gitignore file, even if the rest of
This folder will contain a file named
Node.js which references the rest of the generated IntelliSense code. Drag this file to your
~/Scripts/_references.js and IntelliSense will start working correctly everywhere in your project.
- Gets rid of all non-Node.js globals, including variables declared in other files
- TODO: Supports
fs.readFilefor modules that build APIs from the filesystem
- Supports full Node.js module loading mechanisms; any existing Node.js module should work perfectly (unless it builds APIs from HTTP requests, like
- Runs actual Node.js source from your version of Node (except the
processobjects); should accurately reflect all built-in APIs
- Fully supports Go-to-definition, both for Node.js built-in source and other modules
Writing client-side code
NodeSense will remove all non-Node.js entries from the IntelliSense globals, including the entire DOM API. If your project also contains browser-side code, NodeSense can be configured to provide dual-environment IntelliSense (for systems like browserify, which have both DOM globals and Node.js globals), or to fully restore a pure-browser environment.
To restore browser globals (for dual-environment scripts), call
intellisense.restoreGlobals() (you may also want to set
process.browser = true; to correctly affect browserify-aware modules).
To remove Node.js globals, call
intellisense.removeNodeGlobals() (before calling
These calls should be placed in a separate file that is only referenced using a
/// <reference path="..." /> directive, so that they will be processed by Visual Studio but not Node.js.
How it works
Files in the
templates/ directory will be copied directly to
node_modules/.vs-nodesense/setup, and will only be executed by Visual Studio. These files simulate the core Node.js environment.
The generator will create an index file with a declaration for every module, as well as all aliases for directory and package defaults.
It will also create a reference file for every
require()d file in the target project.
.js (including Node.js built-in modules) files, this file will have a reference tag to the actual JS file, and a call to
intellisense.enterModuleDefinition() for the next file. This is the only way to run my code before running the actual user file; referenced files are always run before any code in the referencing file. Using a reference to the actual JS file allows Go-to-definition to work as expected.
.json files, it will paste the JSON content directly into the generated file and assign it to
.node files are ignored.
It will then create an entry-point file (
node_modules/.vs-nodesense/node.js) with reference tags for the setup files and all of the reference files in order.