Using the os Module

The os module provides an extremely useful set of functions that allow you to get information from the operating system. For example, when accessing data from a stream that comes from the OS, you can use the os.endianness() function to determine whether the OS is big endian or little endian so that you can use the correct read and write methods.

Table 10.1 lists the methods provided by the os module and describes how you can use them.

Image

Table 10.1 Methods that can be called in the os module

To help you visualize using the os module, the code in Listing 10.1 includes each of the os module calls. Figure 10.1 shows the output.

Listing 10.1 os_info.js: Calling methods on the os module


01 var os = require('os'),
02 console.log("tmpdir : " + os.tmpdir());
03 console.log("endianness : " + os.endianness());
04 console.log("hostname : " + os.hostname());
05 console.log("type : " + os.type());
06 console.log("platform : " + os.platform());
07 console.log("arch : " + os.arch());
08 console.log("release : " + os.release());
09 console.log("uptime : " + os.uptime());
10 console.log("loadavg : " + os.loadavg());
11 console.log("totalmem : " + os.totalmem());
12 console.log("freemem : " + os.freemem());
13 console.log("EOL : " + os.EOL);
14 console.log("cpus : " + JSON.stringify(os.cpus()));
15 console.log("networkInterfaces : " +
16             JSON.stringify(os.networkInterfaces()));


Image

Figure 10.1 Output from calling methods on the os module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.14.243