或者实际上问题应该是
如何使用Reactjs和Nodejs将数据写入JSON文件
我是第一个做出反应的人,不了解应该与哪个数据库一起使用。
PS。可以轻松读取json文件
var data = require('./data.json');
但是要写数据,我尝试使用npm'jsonfile '包,并且都尝试使用Nodejs并收到此错误
TypeError: fs.writeFileSync is not a function
我想在全局拦截器中使用服务。
我的代码如下所示:
import { VariablesService } from '../app/modules/variables/variables.service';
@Interceptor()
export class globalInterceptor implements NestInterceptor {
constructor(private service: VariablesService) {
console.log('contructor running', service); //getting null here
}
Run Code Online (Sandbox Code Playgroud)
在server.ts 上,我首先是这样初始化的:
app.useGlobalInterceptors(new globalInterceptor())
Run Code Online (Sandbox Code Playgroud)
但是在注入服务后我必须做一些修改,因为现在需要参数 globalInterceptor()
const variableService = await app.get<VariablesService>(VariablesService);
app.useGlobalInterceptors(new globalInterceptor(variableService));
Run Code Online (Sandbox Code Playgroud)
现在有什么问题是我得到service的null,我无法创建服务的对象。
javascript ×2
android ×1
database ×1
interceptor ×1
json ×1
nestjs ×1
node.js ×1
react-native ×1
reactjs ×1
typescript ×1