Node是什么?Node.js是一个开源和跨平台的JavaScript运行环境;Node.js在浏览器之外运行V8JavaScript引擎(GoogleChrome的核心)。Node.js应用程序运行在单个进程中,无需为每个请求创建一个新线程。Node.js在其标准库中提供了一组异步I/O原生函数(以防止JavaScript代码被阻塞),而Node.js中的库通常是使用非阻塞范式编写的(从而使阻塞行为成为异常而不是常态)当Node.js执行I/O操作(例如从网络读取、访问数据库或文件系统)时,Node.js将恢复操作,而不是阻塞线程和浪费CPU循环等待Node.js和基于js核心(ecmascript)系统级api文件操作,网络编程实现自己的web服务Node解决了什么问题?Web服务器,瓶颈在于并发数(多线程同步)只要多人需要操作同一个资源,就必须通过锁定的javaphp用户来访问服务器。当每个客户端连接到服务器时,都会产生一个新的线程。一个线程占用内存2mb左右,8g内存节点不会新建一个Thread,只是发起一个事件分离前后端,写一些工具库webpack,clinode比较适合web应用场景,返回文件,读写Node核心特性事件驱动Node.jsAPI是基于事件的异步异步阻塞非阻塞(针对不同点)同步和异步,重点看消息通知机制readFilesynchronous体现在对方在等待一件事情的处理结果时是否提供通知服务。如果对方不提供通知服务,则为同步异步。如果对方提供通知服务,则为异步。阻塞和非阻塞程序都阻塞在等待消息结果的状态。在等待一件事情的处理结果的时候,你还做其他事情吗?如果不是,则为阻塞;非阻塞,等待一件事情的处理结果出来了,还要做其他事情吗?如果是这样,它是非阻塞的;Node中的全局对象this和module.exports是===console.log(this);//{}这不是全局的console.log(this===global);//falseconsole.log(this===module.exports);//trueargumentsconsole.log(arguments);//[Arguments]{//'0':{},//'1':[Function:require]{//resolve:[Function:resolve]{paths:[Function:paths]},//main:Module{//id:'.',//path:'/Users/hiraku/myself/architecture-product/node/4.global',//exports:{},//parent:null,//文件名:'/Users/hiraku/myself/architecture-product/node/4.global/index.js',//loaded:false,//children:[],//paths:[Array]//},//extensions:[对象:空原型]{//'.js':[函数],//'.json':[函数],//'.node':[函数],//'.mjs':[函数]//},//cache:[Object:nullprototype]{//'/Users/hiraku/myself/architecture-product/node/4.global/index.js':[Module]//}//},//'2':Module{//id:'.',//path:'/Users/hiraku/myself/architecture-product/node/4.global',//exports:{},//parent:null,//文件名:'/Users/hiraku/myself/architecture-product/node/4.global/index.js',//loaded:false,//children:[],//paths:[//'/Users/hiraku/myself/architecture-product/node/4.global/node_modules',//'/Users/hiraku/myself/architecture-product/node/node_modules',//'/Users/hiraku/myself/architecture-product/node_modules',//'/Users/hiraku/myself/node_modules',//'/Users/hiraku/node_modules',//'/Users/node_modules',//'/node_modules'//]//},//'3':'/Users/hiraku/myself/architecture-product/node/4.global/index.js',//'4':'/Users/hiraku/myself/architecture-product/node/4.global'//}全局键console.log(Object.keys(global));//[//'global',//'clearInterval',//'clearTimeout',//'setInterval',//'setTimeout',//'queueMicrotask',//'clearImmediate',//'setImmediate'//]process进程console.log(Object.keys(process));//['version','arch','platform','release','_rawDebug','moduleLoadList','binding','_linkedBinding','_events','_eventsCount','_maxListeners','domain','_exiting','config','abort','umask','chdir','cwd','_debugProcess','_debugEnd','_startProfilerIdleNotifier','_stopProfilerIdleNotifier','dlopen','uptime','_getActiveRequests','_getActiveHandles','reallyExit','_kill','hrtime','cpuUsage','resourceUsage','memoryUsage','kill','exit','getuid','geteuid','getgid','getegid','getgroups','initgroups','setgroups','setegid','seteuid','setgid','setuid','stdout','stderr','stdin','openStdin','allowedNodeEnvironmentFlags','assert','features','_fatalException','setUncaughtExcepmotionCaptureCallback'、'hasUncaughtExceptionCaptureCallback'、'emitWarning'、'nextTick'、'_tickCallback'、'env'、'title'、'argv'、'execArgv'、'pid'、'ppid'、'execPath'、'debugPort','argv0','_preload_modules','mainModule'process.argv//nodeindex.js--port3000console.log(process.argv);//1.当前节点的执行命令文件//2.当前执行的文件节点是谁+执行文件时,可以传参。这些参数会放在数组的第三项中//3.解析用户传入的参数//['/Users/hiraku/.nvm/versions/node/v11.10.0/bin/node',//'/Users/hiraku/myself/architecture-product/node/global/index.js',//'--port',//'3000']constargvObj=process.argv。slice(2).reduce((memo,current,index,arr)=>{if(current.startsWith('--')){memo[current.slice(2)]=arr[index+1];}返回备忘录;},{});console.log(argvObj);process.platform进程运行的平台console.log(process.platform,'platform');//darwin//win32darwincommander用法constcmd=require('commander');cmd.name('全局节点');cmd.usage('index.js');cmd.version('1.0.0');cmd.option('-p,--port
