Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript, node.js development with Visual Studio 2012 express

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

like image 790
stonedmind Avatar asked Nov 06 '12 11:11

stonedmind


People also ask

Can you use TypeScript with Express?

But what happens when your application server scales, or you're working on a team of developers all across the world? In these instances, TypeScript can help. In this article, we'll cover a beginner-friendly way to set up TypeScript in an Express app, understanding the basic constraints that come with it.

Is TypeScript compatible with Nodejs?

TypeScript is well-established in the Node. js world and used by many companies, open-source projects, tools and frameworks. Some of the notable examples of open-source projects using TypeScript are: NestJS - robust and fully-featured framework that makes creating scalable and well-architected systems easy and pleasant.

Can I use Visual Studio for TypeScript?

For projects developed in Visual Studio 2022, we encourage you to use the TypeScript NuGet or the TypeScript npm package for greater portability across different platforms and environments. For more information, see Compile TypeScript code using NuGet and Compile TypeScript code using tsc.

How do I create a TypeScript project in Visual Studio?

Create a new project. In Visual Studio 2022, choose Create a new project in the start window. If the start window is not open, choose File > Start Window. Type web app, choose C# as the language, then choose ASP.NET Core Web Application (Model-View-Controller), and then choose Next.


2 Answers

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);
like image 127
Fenton Avatar answered Sep 24 '22 02:09

Fenton


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
like image 40
mihai Avatar answered Sep 26 '22 02:09

mihai