8

How can I write, build and run a node.js app in Visual Studio? I install the TypeScript extension on VS and the node.js package. When I create new project of type TypeScript it is only able to write script for browsers only.

Update

I want autocomplete and error handling for node.js libraries

Fenton
  • 241,084
  • 71
  • 387
  • 401
stonedmind
  • 83
  • 1
  • 4

2 Answers2

9

You need to include a type definition for node.js.

This file declares all of the operations for node.js so you can get auto-completion and type safety.

/// <reference path="./node.d.ts" />

var x = new SlowBuffer(5);
Fenton
  • 241,084
  • 71
  • 387
  • 401
  • Thank you, i try it. How about Sublime Text 2? This will work in ST2 too? – stonedmind Nov 06 '12 at 14:46
  • 1
    I am not certain, so may be corrected, but I think Sublime has syntax-highlighting. I don't think it has auto-completion or static-analysis for TypeScript (yet). – Fenton Nov 06 '12 at 14:56
  • You can get node intellisense in Sublime Text 2 using this package/plugin: https://github.com/Kronuz/SublimeCodeIntel – Larry Silverman Apr 11 '13 at 15:45
1

You can just use VS as an editor, there's no need for solution files or anything.

To create a node.js app first install the typescript package:

npm install -g typescript

Then compile your file into javascript:

tsc app.ts

Run your app as a node process:

node app.js
Pero P.
  • 25,813
  • 9
  • 61
  • 85
mihai
  • 37,072
  • 9
  • 60
  • 86