Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 节点Webkit:没有显示任何内容?_Javascript_Node.js_Node Webkit - Fatal编程技术网

Javascript 节点Webkit:没有显示任何内容?

Javascript 节点Webkit:没有显示任何内容?,javascript,node.js,node-webkit,Javascript,Node.js,Node Webkit,我刚刚开始使用Node Webkit,我遇到了一个问题。我已经在下面编写了代码,但是没有显示任何内容,也没有创建我声明要创建的文件。我已经安装了fs和os,但仍然没有运气。我通过将项目文件夹拖动到nw可执行文件中来打开它 Package.json: { "name": "test-app", "main": "index.html", "version": "0.1.0", "window": { "icon": "icon.png",

我刚刚开始使用Node Webkit,我遇到了一个问题。我已经在下面编写了代码,但是没有显示任何内容,也没有创建我声明要创建的文件。我已经安装了fs和os,但仍然没有运气。我通过将项目文件夹拖动到nw可执行文件中来打开它

Package.json:

{
    "name": "test-app",
    "main": "index.html",
    "version": "0.1.0",

    "window": {
        "icon": "icon.png",
        "width": "1300",
        "max_width": "2000",
        "min_width": "500",
        "height": "700",
        "max_height": "1500",
        "min_height": "200",
        "position" : "center"
    },

    "bugs": "http://example.com/bugs"
}
Index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
    <link href="https://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css">

    <script>
        // System Information 
        var os = require('os');

        // File Operations 
        var fs = require('fs');

        // Content
        var content = '';

        // Platform Information 
        content += '[Platform]: ' + os.EOL;
        content += '[OS Type]: ' + os.platform() + os.EOL; // Linux, Darwin Win32, FreeBSD, or SunOs
        content += '[OS Version] ' + os.release() + os.EOL;
        content += '[OS Architecture] ' + os.arch() + os.EOL;
        content += os.EOL;

        // Memory Information
        content += '[Memory]' + os.EOL;
        content += 'Total (Bytes): ' + os.totalmen() + os.EOL;
        content += 'Free (Bytes): ' + os.freenmem() + os.EOL;
        content += 'Free (%): ' + (os.freemem() / os.totalmem() * 100).toFixed(2) + os.EOL;
        content += os.EOL;

        // CPU Information 
        content += '[CPU]: ' + os.EOL;
        content += 'Cores: ' + os.cpus().length + os.EOL;
        content += 'Type: ' + os.cpus[0].model + os.EOL;

        fs.writeFile('./sysinfo.txt', content, function (err) {
          if (err) {
            alert('Error writing file');
          }
          else document.write("Successfully wrote to file.");
        });
    </script>
  </head>
  <body>
  </body>
</html>

试验
//系统信息
var os=要求(“os”);
//文件操作
var fs=需要('fs');
//内容
var内容=“”;
//平台信息
content+='[平台]:'+os.EOL;
content+='[OS类型]:'+OS.platform()+OS.EOL;//Linux、Darwin Win32、FreeBSD或SunOs
content+='[OS Version]'+OS.release()+OS.EOL;
content+='[OS架构]'+OS.arch()+OS.EOL;
内容+=os.EOL;
//记忆信息
content+='[Memory]'+os.EOL;
content+=“总计(字节):”+os.totalman()+os.EOL;
content+=“Free(字节):”+os.freenmem()+os.EOL;
content+=“Free(%):”+(os.freemem()/os.totalmem()*100).toFixed(2)+os.EOL;
内容+=os.EOL;
//CPU信息
content+='[CPU]:'+os.EOL;
content+='核心:'+os.cpu().length+os.EOL;
content+='类型:'+os.cpu[0].模型+os.EOL;
fs.writeFile('./sysinfo.txt',内容,函数(err){
如果(错误){
警报(“写入文件时出错”);
}
else document.write(“成功写入文件”);
});

请检查index.html中的打字错误

content+='总计(字节):'+os.totalmen()+os.EOL;--应该是os.totalmem()

content+='空闲(字节):'+os.freenmem()+os.EOL;--应该是os.freemem()

及 content+='类型:'+os.cpu[0].型号+os.EOL;--os.CPU()[0]。型号

替换

os.CPU[0]。模型

os.cpus()[0].model

前一段时间已经修复了所有的打字错误,但仍然不起作用。你打算如何运行它?在project folder just run nwYes中,它显示一个空白页。