Node.js + TypeScript = AwesomeYou can use TypeScript to write maintainable Node.js apps. Here's how to set up a project in VS Code.
Create the ProjectFirst create a project folder. Next I like to use "npm init" to set up the package.json file for the project. This will make it easy to track your npm dependencies.
Now you can open the project folder in VS Code.
Set up TypeScript CompilerTo set up the compiler create a file called tsconfig.json and add the following into it.
The important bit is to set the module to "commonjs" because this is the module loading system used by Node.js.
Start ProgrammingCreate your main entry point TypeScript file. I usually call mine "main.ts".
Now you can add any supporting TypeScript files. To turn on the TS compiler to watch for changes and automatically compile go to the Tasks menu, select Run Build Task and select "tsc: watch" from the menu.
Although you can use the require keyword in your TypeScript files to import npm packages, you should use a TS import statement instead. Otherwise you will not get code hints.
import * as fs from "fs";
let myModule = require("./myModule");
Note also that you probably don't want to use "export default" in your TypeScript file or you will have to reference the default item using the default keyword, which is a little awkward...
let something = myModule.default();