node.js - 如何在 Angular 8 中使用 nodejs 模块?
问题描述
我不能在我的 Angular 8 应用程序中使用 nodeJS 全局模块。例如“fs”模块。我想通过使用 nodeJS 'fs' 模块来执行 writeFile 和 readFile 操作。我尝试了很多方法,但无法在我的 Angular 8 应用程序中访问这些模块。请帮助我...
解决方案
如果您正在使用 Angular 开发 Electron 应用程序,则必须进行一些工作来访问节点 api。
安装ngx-electron并输入 NgxElectronModule(按照
Installation
自述文件中的说明进行操作)。在需要调用 node api 的地方注入 ElectronService。
通过 . 导入您需要的包
this._electronService.remote.require(string)
。
D:\
这是通过节点 api获取文件列表的示例。
const fs = this.electronService.remote.require('fs');
console.log(fs.readdirSync('D:\\'));
推荐阅读
- agens-graph - 在 AgensGraph 上是否有“类似”的替代方案?
- mysql - 带有搜索查询的 MYSQL BLOB 与 TEXT 字段
- java - 如何将 Recyclerview 的 OnClickListener 放入 Activity
- python - 如何在不导入的情况下引用另一个文件中的变量?
- javascript - 在 Angular 项目中实施 xApi 技术
- javascript - 使用 JavaScript 的页眉和页脚的 HTML 到 MS 字转换
- database - 是否可以在不使用 xampp 的情况下运行带有数据库的系统?
- angular - 我知道 Bootstrap,我可以在同一个项目中使用 MD Bootstrap 和/或 Angular Material 组件吗?
- json - 使用 jq 检查 package.json 中是否存在“builds”部分
- android - 无法为 Flutter 应用生成签名的 apk