I want to use import fs from 'fs'
in JavaScript. Here is a sample:
import fs from 'fs'
var output = fs.readFileSync('someData.txt')
console.log(output)
The error I get when I run my file using node main.js
is:
(function (exports, require, module, __filename, __dirname) { import fs from 'fs
'
^^^^^^
SyntaxError: Unexpected token import
What should I install in Node.js in order to achieve importing modules and functions from other places?
import fs from 'fs/promises'
syntax, on earlier versions, you'll have to create an alias usingimport { promises as fs } from syntax
– Dichy