Module OS

Represents an operating system-specific module

Os.cpu () Indicates the number of CPU cores in the current operating system

Open nodeJS source code libs. Summary: c++ module output, and this output, it is using the v8 library after processing, then the output of these things, will eventually be directly called in JS.

EventEmitter module observer mode

libs.js
const EventEmitter = require('events').EventEmitter;

class GeekTime extends EventEmitter {
  constructor() {
    super(a);setInterval(() = > {
      this.emit('newlesson', {price: Math.random()*100})},3000)}}module.exports = GeekTime
Copy the code
index.js
const GeekTime = require('./libs')

const geekTime = new GeekTime;
geekTime.addListener('newlesson'.(res) = > {
  console.log('get', res)
})
Copy the code