Reputation: 103
I start to learn typescript today, and there's a problem.
Here is the filetree(after compiling):
dist
index.js
src
data.txt
index.ts
Here is ./src/index.ts:
import { readFileSync } from 'fs';
let data = readFileSync('./data.txt');
console.log(data);
After compiling with command "tsc", it creates ./dist/index.js, absolutely the file data.txt cannot be read correctly. How to make it the right path?
Upvotes: 2
Views: 13004
Reputation: 2701
Usually you are not supposed to put data in src
folder. There are several ways if you really want to do so:
data.txt
to dist while compiling typescriptpath.join(__dirname, "../src/data.txt")
"../src/data.txt"
directlyUpvotes: 4