Its a commonjs module and not an es6 module. So you cannot use the
import {EOL} from 'os'
style because EOL isn't exported.
You import these modules using either
import * as os from 'os';
or
import os = require('os');
the former being more common as far as I've seen.
import * as os from 'os';
const { EOL } = os;
console.log("hello" + EOL + "world");
you may or may not need to npm install @types/node
for typescript to know about os
. with the types installed you can explicitly tell node to load the types up with
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"types": [
"node"
]
}
}