nodejs http url fs模組搭建服務

2021-10-08 08:56:15 字數 1861 閱讀 8400

var fs =

require

('fs');

// 如果檔案存在 則向檔案中寫入內容 如果檔案不存在則建立該檔案並寫入內容

var writestream = fs.

createwritestream

('要寫入內容的檔案位址'

) writestream.

write

('要寫入的內容'

,'utf-8');

// 用來標記結尾

writestream.

end(

) writestream.on(

'finish'

,function()

) writestream.on(

'error'

,function()

)// 讀取檔案流的方法

var readstream = fs.

createreadstream

('要讀取內容的檔案位址');

var text =

''// 監聽讀流的過程

readstream.on(

'data'

,function

(chunk)

)// 監聽讀流結束

readstream.on(

'end'

,function()

)// 監聽發生的錯誤

readstream.on(

'error'

,function()

)// 利用管道流實現檔案複製

// 獲取檔案的副檔名

var extname = path.

extname

(pathname)

; pathname = pathname ==

'/'?

'預設渲染的html檔案的位址'

: pathname

function

getexttype

(ext)

return str

}var type =

getexttype

(extname)

fs.readfile

('./static'

+ pathname,

function

(err, data)

;charset=utf-8`})

res.

write

(errpage)

res.

end()}

)}else

;charset=utf-8`})

res.

write

(data)

res.

end()}

})})

.listen

(3000

,function()

)

搭建遠端juypter notebook 伺服器

jupyter notebook generate config2.開啟ipython建立乙個密碼 in 1 from notebook.auth import passwd in 2 passwd enter password verify password out 2 sha1 把密文記錄下來 ...

express mockjs 搭建mock伺服器

安裝express mockjs npm install express mockjs d 安裝熱更新 supervisor npm install supervisor 原始碼 if req.method options res.send 200 讓options請求快速返回 else next ...

springcloud搭建eureka服務

案例建立的工程名為 springcloue parent 02 修改pom檔案 pom org.springframework.cloud spring cloud dependencies greenwich.release pomimport 案例子工程名為 eureka com.yl spri...