node入门笔记

node可以理解为一门后台语言 ,可以写接口,写后台,node和js思想相似,说白了,就是拿js思想写后台,搭建项目环境

使用js的语法,js+js扩展,以模块化的形式管理代码,使用的是commonJs规范

Node.js中的全局对象是global,所有全局变量都是global对象的属性,在Node.js中我们可以直接访问到global的属性,不需要我们在应用中包含它

两种编写形式
交互式 > node 
文件启动 *> node 文件名(.js 可以省略)

node 启动 文件启动

argumenets.callee  -->指向函数原型

function (exports, require, module, __filename, __dirname) {
var a=1;
console.log(arguments.callee.toString())
}

说明node每次运行的时候node文件默认给我们包了一层函数,所以说一个文件就是一个模块

exports -》单一 暴露


require  引入

1系统模块 ->node官网   require('http')

2第三方模块-》npm下载的   require('http')

3自定义模块 -》自己写的    require('./name')


module -》对象   module.exports 暴露 

exports可以做到的module.exports都可以做到,module.exports可以做到exports不一定能做到


__filename 文件路径

__dirname 文件夹路径

posted @ 2018-09-11 15:46  小宋不摸鱼  阅读(373)  评论(0编辑  收藏  举报