【问题标题】:how to include http,fs modules inside node webkit如何在 node webkit 中包含 http、fs 模块
【发布时间】:2015-08-17 11:40:32
【问题描述】:

我正在创建一个简单的节点网络工具包应用程序。我有输入类型的表单,在提交表单时我想将此浏览的文件保存到临时文件夹中。如何使用 node web kit 做到这一点。

一个示例代码对我的学习会更有帮助。

【问题讨论】:

    标签: angularjs node.js node-webkit


    【解决方案1】:

    使用 NW 时,您应该考虑在桌面应用程序工作流程中,您不需要像创建 http 服务器来接收文件那样的服务器端,而是可以从“客户端”端执行文件操作,

    要选择文件,您可以使用File dialogs 此代码解释如何选择它并要求 fs 模块使用它:

    <script>
      // requiring the fs module
      var fs = require('fs');
      function chooseFile(name) {
        var chooser = document.querySelector(name);
        chooser.addEventListener("change", function(evt) {
          // this will print the selected file
          console.log(this.value);
          // from here you could use the fs module required above to do whatever you need with the file, read it or write it
        }, false);
    
        chooser.click();  
      }
      chooseFile('#fileDialog');
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 2015-08-21
      • 2018-01-05
      • 2016-12-20
      • 1970-01-01
      相关资源
      最近更新 更多