博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Node.js] CommonJS Modules
阅读量:4593 次
发布时间:2019-06-09

本文共 786 字,大约阅读时间需要 2 分钟。

CoomonJS modules provide a clean syntax for importing dependencies. This lesson will take a look at the basics of using CommonJS modules.

app.js

var dep = require('./dep');console.log(dep); // Exports a string back

dep.js

module.exports =  "Exports a string back";

 

You can exports anything, such as a function:

app.js

var dep = require('./dep');console.log(dep()); // Export a function back

dep.js

module.exports = function() {    return "Exports a function back";}

 

Exprots multi-value:

app.js

var dep = require('./dep');console.log(dep.foo, dep.bar); //foo, bar

dep.js

module.exports = {    foo: "foo",    bar: "bar"}

 

Normally, you should do like this, using exprots object directly:

dep.js

exports.foo = "foo";exports.bar = "bar";

 

转载于:https://www.cnblogs.com/Answer1215/p/4152377.html

你可能感兴趣的文章
IOS 7 UI 的适配
查看>>
变量的引用类型和非引用类型的区别
查看>>
drawable以及Bitmap的基本操作
查看>>
小广告效果
查看>>
Oracle&MySql&SqlServer分页
查看>>
Django 查询很经典的
查看>>
【Mood-1】这么长时间都是在收集好的技术博客,以后也要在csdn上留下自己的足迹才好嘛...
查看>>
2017-11-8—自动控制原理在软硬件方面上的应用和体现
查看>>
五大行获央行5000亿SLF 相当于降准0.5%
查看>>
Nginx+Tomcat负载均衡配置
查看>>
常用模块(一)
查看>>
mysql查询区分大小写与自定义排序
查看>>
string
查看>>
9.indicate、xutils、json
查看>>
JCEF3——谷歌浏览器内核Java版实现(一):使用jawt获取窗体句柄
查看>>
多态与异常处理课后习题
查看>>
孕龙逻辑分析仪 ZeroPlus Logic Analyzer
查看>>
NativeXml: A native Delphi XML parser and writer
查看>>
Win7 开启显示快速启动工具栏,发送到快速启动右键菜单
查看>>
回忆我是如何赢得一次踢毽子比赛
查看>>