nodejs漸入佳境[3]-require匯入模組
阿新 • • 發佈:2018-11-30
require 匯入其他檔案
require可以執行其他檔案的內容。
新建檔案: nodes.js:
1 |
console.log('start nodes.js'); |
app.js:
1 |
//列印字串 |
開啟控制檯,在當前目錄下輸入:
1 |
> node app.js |
輸出字串
1 |
Start app. |
require 匯入屬性
nodes.js:
1 |
console.log('start nodes.js'); |
app.js:
1 |
//列印字串 |
開啟控制檯,在當前目錄下輸入:
1 |
> node app.js |
檔案中儲存:Hello jackson age 25
require 匯入函式
nodes.js:
1 |
console.log('start nodes.js'); |
app.js:
1 |
console.log('Start app.'); |
開啟控制檯,在當前目錄下輸入:
1 |
> node app.js |
輸出字串
1 |
Start app. |
require 匯入帶參函式
nodes.js:
1 |
console.log('start nodes.js'); |
app.js:
1 |
//列印字串 |
開啟控制檯,在當前目錄下輸入:
1 |
> node app.js |
輸出字串
1 |
Start app. |
版權宣告: 本部落格所有文章除特別宣告外,均採用 CC BY 4.0 CN協議 許可協議。轉載請註明出處!