Os.EOL in Typescript + Node.js
3 answers
Its a generic module, not an es6 module. Therefore you cannot use
import {EOL} from 'os'
since EOL is not exported.
You import these modules using
import * as os from 'os';
or
import os = require('os');
the first one was more common as far as I saw.
import * as os from 'os';
const { EOL } = os;
console.log("hello" + EOL + "world");
you may need npm install @types/node
os. with types set you can explicitly tell node to load types with
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"types": [
"node"
]
}
}
+1
source to share
What's wrong with the built-in node function?
const os = require('os');
console.log(os.EOL);
or in TypeScript style:
import os = require('os');
console.log(os.EOL);
using ES module syntax with import from CommonJS package is an unstable situation at the moment and should be used with caution if ever. This is especially true when using TypeScript with
--module commonjs
0
source to share