Node.js的基本模块学习(一)
来源:互联网 发布:win10启用不了网络发现 编辑:程序博客网 时间:2024/06/07 08:57
首先写一个hello.js文件:
'use' strict; var s='hello'; function greet(name){ console.log(s+','+name+'!'); }module.exports=greet;
首先看到,函数greet()是hello.js中的,最后面一条语句,将函数greet作为模块输出,个人理解就是类似java中的public属性,那么其他的js文件就可以调用这个函数.
再写一个main.js文件:
'use strict';//引入hello模块:var hi=require('./hello');var s='World!';hi(s);//输出hello,World!
此时可以注意点,hi就相当于hello.js文件中的greet()函数了,通过require()函数将hello模块中暴露的greet()函数传给了变量hi../hello是因为两个文件在同一个目录上,未来避免出错,最后写绝对路径.
阅读全文
0 0
- Node.js的基本模块学习(一)
- 我的node.js学习(一)querystring模块基本用法
- node.js基本模块学习(一) fs模块
- Node.js的基本模块学习(三)
- Node.js基本模块学习(二)
- node.js基本模块学习(二) stream
- Node.js基本模块
- node js 学习笔记(一) 常用模块介绍
- Node.js基本模块stream
- Node.js基本模块http
- Node.js模块、包的学习笔记
- node.js学习一(node入门)
- Node.js学习笔记(2)——新建简单的node.js模块
- 学习node.js(一)
- node.js学习(一)
- node.js学习(十三、Buffer模块)
- node.js学习(十四、Console模块)
- node.js学习(十六、DNS模块)
- UVa 227 Puzzle AC
- SSH整合:No object in the CompoundRoot has a publicly accessible property named 'x'
- pytorch loss function 总结
- C++实验5
- Latex--将参考文献号设为上标,并加方括号!
- Node.js的基本模块学习(一)
- APP性能-网络优化-工具篇
- 在Linux上生成java程序的火焰图
- 使用VC++实现 客户端和服务端通信 获取本机IP地址
- Sourcery CodeBech Lite下载
- 7. Reverse Integer
- 穿越雷区
- H264 ES PS TS 流的区别
- 【转载】我为什么鼓励工程师写blog