CommonJS_Node模块化教程
来源:互联网 发布:淘宝学习zz px 编辑:程序博客网 时间:2024/06/17 23:34
Node.js模块化教程
- 下载安装node.js
创建项目结构
|-modules|-module1.js|-module2.js|-module3.js|-app.js|-package.json{ "name": "commonJS-node", "version": "1.0.0"}
- 下载第三方模块
- npm install uniq –save
模块化编码
module1.js
module.exports = { foo() { console.log('moudle1 foo()') }}
module2.js
module.exports = function () { console.log('module2()')}
module3.js
exports.foo = function () { console.log('module3 foo()')}exports.bar = function () { console.log('module3 bar()')}
app.js
/** 1. 定义暴露模块: module.exports = value; exports.xxx = value; 2. 引入模块: var module = require(模块名或模块路径); */"use strict";//引用模块let module1 = require('./modules/module1')let module2 = require('./modules/module2')let module3 = require('./modules/module3')let uniq = require('uniq')//使用模块module1.foo()module2()module3.foo()module3.bar()console.log(uniq([1, 3, 1, 4, 3]))
- 通过node运行app.js
- 命令: node app.js
- 工具: 右键–>运行
阅读全文
0 0
- CommonJS_Node模块化教程
- CommonJS-Browserify模块化教程
- ThinkPHP教程--14--模块化设计
- JS模块化工具requirejs教程
- JavaScript模块化实现库教程
- JS:模块化工具requirejs教程
- JS模块化工具requirejs教程
- JS模块化工具requirejs教程
- JS模块化工具requirejs教程
- Struts教程-Struts模块化编程教程
- Struts模块化编程经典实战教程(一)
- Struts模块化编程经典实战教程(二)
- Struts模块化编程经典实战教程(一)
- Struts模块化编程经典实战教程(二)
- JS模块化工具requirejs教程(二):基本知识
- JS模块化工具requirejs教程(二):基本知识
- JS模块化工具requirejs简易教程
- JS模块化工具requirejs教程(二):基本知识
- Redis中PipeLine使用(11)
- 2017-07-03(树形DP)
- 软考,网络工程师教程(第四版)2017最新视频教程
- blur --后台点击更改表格;
- 微信小程序审核没有通过的原因
- CommonJS_Node模块化教程
- ViewPager 详解(一)---基本入门
- CommonJS-Browserify模块化教程
- 偏振镜头的应用
- codevs 2913 建筑抢修
- iOS应用架构现状分析
- Appcan+vue+vux+webpack开发app(原创)
- 【Linux】中的进程信号三张表
- 6月28