EN
TypeScript / Node.js - install Node types (type declarations)
6 points
In this article, we would like to show you how to install and use Node types in TypeScript under Node.js.
Simple steps:
1. install TypeScript Node.js types, using:
xxxxxxxxxx
1
npm install --save-dev @types/node
2. add packages using import
keyword, e.g.:
xxxxxxxxxx
1
import * as path from 'path';
2
3
path
In this example, after installing Node types with the above command, we import and use the path
module using the import
keyword.
xxxxxxxxxx
1
import * as path from 'path';
2
3
// example paths
4
const absolutePath: string = 'C:/projects/app/index.js';
5
const relativePath: string = './index.js';
6
7
// check if path is absolute
8
const result1: boolean = path.isAbsolute(absolutePath);
9
const result2: boolean = path.isAbsolute(relativePath);
10
11
console.log(result1); // true
12
console.log(result2); // false
Output:
xxxxxxxxxx
1
true
2
false