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:
npm install --save-dev @types/node
2. add packages using import
keyword, e.g.:
import * as path from 'path';
path...
Practical example
In this example, after installing Node types with the above command, we import and use the path
module using the import
keyword.
import * as path from 'path';
// example paths
const absolutePath: string = 'C:/projects/app/index.js';
const relativePath: string = './index.js';
// check if path is absolute
const result1: boolean = path.isAbsolute(absolutePath);
const result2: boolean = path.isAbsolute(relativePath);
console.log(result1); // true
console.log(result2); // false
Output:
true
false