0
I have a code in Typescript (Nodejs-10.6.0) and need to create a variable that will recover the contents of a JSON file.
I have tried to import the contents from the file in the following ways:
1. import { orderPayload } = require('../../events/qa/myfile.json');
2. import { orderPayload } = '../../events/qa/myfile.json';
3. const orderPayload: Order = require ('../../events/qa/myfile.json');
4. const orderPayload= require ('../../events/qa/myfile.json');
Tslint shows the following errors:
1. TS1141 - String Literal expected, Required statement not part of a import statement (no-var-required)
2. String Literal expected
3. Required statement not part of a import statement (no-var-required)
4. Required statement not part of a import statement (no-var-required)
Is there any way to import the contents of this JSON file into the variable orderPayload
without using the FS file system module of Nodejs?
the file
JSON
has akey
with the nameorderPayload
?– Thiago Magalhães
No. Only has 2 keys 'Metadata' and 'payload'.
– zwitterion
A question: what was the problem of using FS? I thought it was the most common way to upload files. By the way, since it is Node should have library ready to load JSON that uses FS internally, if you just want a cleaner code.
– Daniel