Node-persist:initSync 不是函数

Node-persist : initSync is not a function

我刚开始学习Nodejs。
我正在学习持久模块。这是我的代码:

var storage = require('node-persist');
// console.log(storage);
storage.initSync();

但是我遇到了这个错误

TypeError: storage.initSync is not a function

而console.log存储时,只有create和init

{ create: [Function], init: [Function] }

我的代码哪里有问题吗?

您应该检查 3.0.0 更改日志

All the *Sync functions were removed, every operation is now asynchronous

https://www.npmjs.com/package/node-persist#300-change-logs

它在 V 3.0 中发生了变化。但如果你想以同步方式使用,你可以说:

var storage = require('node-persist');
await storage.initSync();