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:
扫描二维码关注公众号,回复:
4295176 查看本文章
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协议 许可协议。转载请注明出处!