node常用模組整理

2021-08-14 08:03:56 字數 1164 閱讀 8404

/*

* 一 util

*      是 node 裡面乙個工具模組 ,node 裡面幾乎所有的模組 都會用到 在這個模組

*  功能:

*      1 實現繼承 這是主要功能

*      2 實現物件的完整輸出

*      3 實現判斷資料型別**/

//引入工具類

var util = require("util");

function parent()

}//繼承parent的外加屬性 為外部繼承

parent.prototype.getname = function()

function child()

//實現child繼承parent

// 工具類 util 裡面的inherits 只能繼承原型鏈(prototype)的方法和屬性,無法繼承類自有(直接寫在類裡面的)的方法和屬性

util.inherits(child,parent);

console.log(child)

/**path模組

** 功能:格式規範化路徑**/

//引入模組

var path = require("path");

var str = "../d\/d/fg/gg//.l";

//格式化不規範的路徑

console.log(path.normalize(str));

//拼接路徑

var res = path.join("s/b/c/d","../f");

console.log(res);

//目錄操作部分

//1.讀取目錄

fs.readdir("dir1",function(err,files)else

});//2.建立目錄

fs.mkdir("dir2",0777,function(error)else

});//3.判斷檔案或者資料夾是否存在

//4.修改檔名

Node常用內建模組 stream

檔案流讀取文字內容 use strict var fs require fs var rs fs.createreadstream sample.txt utf 8 rs.on data function chunk rs.on end function chunk rs.on error func...

Ansible常用模組整理

一 新增ansible主機 vim etc ansible hosts server1 新增以下內容 192.168.61.130 ansible ssh port 22 ansible ssh user root ansible ssh pass redhat 192.168.61.131 ans...

node核心模組path,fs的常用api

node作為js在服務端執行的容器,以及npm包依賴管理工具,使得node的應用越來越廣泛。node有很多模組和api,這也導致很多人不知道怎麼學習node,而掌握其核心模組的核心api是首要的。fs模組 提供檔案的讀寫操作,具有非同步和同步的api fs.readfileasync path,ut...