The core module of Node.js

  • Node provides a lot of server-level functionality for JavaScriptAPI, theseAPIMost of them are packaged into a named oneThe core moduleIn the now. For example, file manipulationfsCore modules,httpservice-builtThe HTTP module.pathPath operation module,osOperating system information module, etc
  • To say that this module is a core module, you must immediately think that if you want to use it, you must:
var fs = require(" fs ")var http = require('http')
Copy the code
  • You can find these modules on NodeChinese: nodejs.cn/api/

Case: Get some information about the OS

// It is used to obtain machine information
var os = require('os')

// Get the CPU information of the current machine
console.log(os.cpus())
Copy the code
  • Eight modules appear, representing eight cores

  • Obtaining Memory Information
var os = require('os')
/ / the memory memory
console.log(os.totalmem())
Copy the code



The units above are bytes, divided by 1024, which equals approximately 8 gigabytes of memory

Example: Get information used to manipulate paths

// Used to manipulate paths
 var path = require('path')
 
// Get the extension part of a path
 console.log(path.extname('c:/a/b/c/d/hello.txt'))
Copy the code