做网站得多钱,北京公司黄页大全,全球包装设计网,网络管理系统中驻留在被管对象认识 node.js
Node.js 是一个独立的 JavaScript 运行环境#xff0c;能独立执行 JS 代码#xff0c;可以用来编写服务器后端的应用程序。基于Chrome V8 引擎封装#xff0c;但是没有 DOM 和 BOM。Node.js 没有图形化界面。node -v 检查是否安装成功。node index.js 执行该文…认识 node.js
Node.js 是一个独立的 JavaScript 运行环境能独立执行 JS 代码可以用来编写服务器后端的应用程序。基于Chrome V8 引擎封装但是没有 DOM 和 BOM。Node.js 没有图形化界面。node -v 检查是否安装成功。node index.js 执行该文件夹下的 index.js 文件。
modules 模块化
commonJS 写法
// a.js
const Upper (str) {return str.substring(0,1).toUpperCase() str.substring(1)
}
const fn () {console.log(this is a)
}
// 接口暴露方法一
// module.exports {
// upper: Upper,
// fn
// }
// 接口暴露方法二
exports.upper Upper
exports.fn fn// index.js
const A require(./modules/a)
A.fn() // this is a
console.log(A.upper(hello)) // HelloES 写法
需要先 npm install 安装依赖生成 node_modules 文件夹然后在 package.json 中配置 type: module,之后才可以使用这种写法。
// a.js
const Upper (str) {return str.substring(0,1).toUpperCase() str.substring(1)
}
const fn () {console.log(this is a)
}
// 接口暴露方法一
// module.exports {
// Upper,
// fn
// }
// 接口暴露方法二
// exports.upper Upper
// exports.fn fn
// 接口暴露方法三
export {Upper,fn
}// index.js
// const fnn require(./modules/a)
// 注意此时导入a.js 文件必须加上 js 后缀
import { Upper } from ./modules/a.js
console.log(Upper(hello)) // Hello