admin管理员组文章数量:1333736
I will read/write a file with angular from/to my hdd. I normaly use node module "fs". Whats the best practice to bine this module with angular to use it in node webkit?
Thanks!
Edit: (can't use require in angular to load npm modules. any ideas?)
.service("WindowService", WindowService);
function WindowService() {
this.gui = require('nw.gui');
}
I will read/write a file with angular from/to my hdd. I normaly use node module "fs". Whats the best practice to bine this module with angular to use it in node webkit?
Thanks!
Edit: (can't use require in angular to load npm modules. any ideas?)
.service("WindowService", WindowService);
function WindowService() {
this.gui = require('nw.gui');
}
Share
Improve this question
edited Oct 7, 2016 at 15:43
rzelek
4,0231 gold badge36 silver badges36 bronze badges
asked Feb 4, 2016 at 9:51
robertrobert
8573 gold badges10 silver badges25 bronze badges
0
3 Answers
Reset to default 2i wrote this example, if you had any questions as to how things are working? you may also want to check out this as well, which the former example uses to work outside of the browser.
but since the main question is regarding the error involving the require
function, i will elaborate. require
is a function implemented by the node runtime, it was added because there was no way initially built into js to import code from fileA to fileB. so when your in the browser you dont need to require anything, just make sure you have the file added to the html ie: <script src="my/file.js"></script>
. but if you really want to do require in the browser, just use browserfy.
I have similar experiences to you. I usually wrap modules to services and use it as normal angular service with DI.
This makes code more readable and maintanable. Also, when you want to change node module, you are changing it in one place.
for your project, i will look to socket.io > for broadcast websocket, and update your angular scope... shokidar > better than FS, with less bug than fs
本文标签: javascriptread or write file to filesystem with angularStack Overflow
版权声明:本文标题:javascript - read or write file to filesystem with angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742331550a2454796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论