0
votes

I have just started with Node-Webkit and I have an issue. I have coded my code below but nothing is displaying and no file is created which I declared to be created. I have npm installed fs and os but still no luck. I open it by dragging the project folder into nw executable

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>
2

2 Answers

0
votes

Please check the typo errors in your index.html

content += 'Total (Bytes): ' + os.totalmen() + os.EOL; -- should be os.totalmem()

content += 'Free (Bytes): ' + os.freenmem() + os.EOL; -- should be os.freemem()

and content += 'Type: ' + os.cpus[0].model + os.EOL; -- os.cpus()[0].model

0
votes

Replace...

os.cpus[0].model

With...

os.cpus()[0].model