Server/NodeJS & NestJS

NodeJS) 서버에서 HTML 파일 읽기

Juzdalua 2023. 4. 3. 19:12

path를 이용해서 경로를 수정한다.

fs를 이용해서 파일을 읽어온다.

 

typescript 기반 ts파일은 dist 폴더를 벗어나 실제 파일이 위치한 곳으로 이동해야한다.

 

import fs from 'fs';
import path from 'path';

const nowPath = path.join(__dirname, '..', 'src', 'test.html');
const mailMessage: string = fs.readFileSync(nowPath, {encoding: 'utf-8'});