Skip to Content
Node.js物聯網裝置開發
book

Node.js物聯網裝置開發

by Patrick Mulder, Kelsey Breseman
August 2017
Intermediate to advanced
272 pages
5h 32m
Chinese
GoTop Information, Inc.
Content preview from Node.js物聯網裝置開發
229
附錄 A
Node.js
基本模組
JavaScript 語言中,模組代表著程式庫的概念,裡頭存放著函式、物件、或是其他可
重複用於不同專案的東西。幫助我們處理檔案、資料、以及與外部裝置進行溝通。
檔案系統模組
假設你想要開啟檔案,讀取其中的資料,Node.js 並未內建提供存取檔案的函式,而是
模組
來處理檔案。
如果你的電腦系統是 Mac OS X Unix,許多嵌入式裝置連接後,將會
以檔案的形式出現在檔案系統的
/dev/
目錄裡。如此一來,從主機電腦讀
取、寫入、控制嵌入式裝置的動作,就會類似於讀寫檔案的方式。
載入檔案模組的程式碼如下:
var fs = require('fs');
載入
fs
模組後,你就擁有眾多與檔案相關的物件和類別,輔助你在 JavaScript 程式碼裡
存取檔案。
請把 Node.js API 文件加入書籤,方便隨時查閱。其中跟檔案系統相關的
部分在
https://nodejs.org/api/fs.html
230
|
附錄 A Node.js
讓我們到 Node.js 主控台下,玩一玩這個檔案系統模組吧!首先,以下列指令開啟
Node.js 主控台:
$ node
然後,要求匯入該模組:
> var fs = require('fs');
{ Stats: [Function], ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

金融人工智能:用Python实现AI量化交易

金融人工智能:用Python实现AI量化交易

Yves Hilpisch
快学熟用D3

快学熟用D3

Philipp K. Janert

Publisher Resources

ISBN: 9789864764594