【发布时间】:2020-04-10 12:46:17
【问题描述】:
我正在尝试返回一个 json 文件作为控制器响应,但我无法获取 json 的内容。
import { Controller, Get, Res, HttpStatus, Query } from '@nestjs/common';
import { Response } from 'express';
import * as MOCKED_RESPONSE_TS from './data/payment-method.data'; // this ts file is imported fine
const MOCKED_RESPONSE = require('./data/payment-method-mock'); // this json file is not found
@Controller('commons')
export class CommonController {
@Get('/payment-method')
getPaymentMoethod(@Res() res: Response): any {
res.status(HttpStatus.OK).send(MOCKED_RESPONSE);
}
}
实际上日志返回:
Error: Cannot find module './data/payment-method'并且应用程序没有编译
我已经使用 express(甚至使用 typescript)完成了这项工作,并且工作正常。
我不知道我是否必须设置我的项目来读取 jsons(我是 Nest 新手)。到目前为止,我已经创建了一个 typescript 文件,该文件导出了一个带有 json 内容的 const,并且我成功地将其命名为
【问题讨论】:
-
你得到了什么?
标签: json typescript nestjs