Node.js Core Modules 核心模组 The modules do need to use NPM install

窦涵忍
2023-12-01

The modules do need to use NPM install:

These modules installed locally  with you install NODE js 

1. Path module

LOAD:

var path = require("path")

Using:

path.basename(__filename)  # pluck out the file name from the path

path.join(*args)  join a series of path name with "/"

 

2. Utilie module

var util = require("util)

util.log()  have a same result as console.log(), but it has log the time of the code loading time staple 

//++++++++++++++

util.inherits(object1, ob2)

help ob1 to inherits all of function in ob2

 

3. V8

Get current memory

var v8 = require("v8")

util.log(v8.getHeapStatistics())

=========================================================================

4. Reading module

ask question to user in termial and saving those answers 

var readline = require('readline')

var rl = readline.createInterface(process.stdin, process.stout)

# readline helps us to control thoes object 

rl.question(string, function(answer))

# ask question

# handle the answer

rl.setPrompt('');

in the question() function to repeat the question prompt

 

5. EventEmitter

require('events');

var emitter = new events.EventEmitter();

emitter.on('customEvent', function(string));

emitter.emit('customEvent', string1)

emit will push the second argument into customEvent and run it! \

 

 类似资料: