Node.jsでprocessに対する理解

43787 ワード

APIの手順に従って勉強します.中の説明はAPI上のものです.このブログはノートに似ています.
私の個人ブログ何俊才の個人ブログを訪問してください.これはNodeJSに基づいて独立して作ったブログです.コードは基本的に自分の一行のコードです.不完全なところがたくさんあります.このブログを訪問したいという読者の意見があります.もっとよく改善するようにします.(勉強ですから、一部の枠組みは役に立たないです.自分の能力範囲内で実現できるのは自分で手動で実現します.)
/*console.log(__filename);         ---        ----      
require("./2.js");     ./        nodenode_module
require("D:\\Nodejs\\     \\1\\ECMA\\2.js");            
require("./2")      
1.                  
2..js
3.      ,             .json    
4,.node    
5.            
    ->.js->.json->.node->  

process      ,node.js   .node.js           .

  API      process
1 abort----  node.js      ,     core  
        
setInterval(function () {
    process.abort();
},5000);
       ,       core

2 arch     node.js             (arch       )
console.log(process.arch);         x64,        arm      

3 argv          ,         node.js         
  console.log(process.argv);
      
[ 'C:\\Program Files (x86)\
odejs\
ode.exe',
'D:\\Nodejs\\ \\1\\ECMA\\1.js' ] 2 . process.execPath , node.js . node.exe , js ( ) Dos node.js console.log(process.argv0); process.argv 4 channel API : node.js IPC Channel ,process.channel IPC Channel , undefined IPC Channel---- undefined 5 chdir node.js , , : node.js cwd (cwd node.js ) console.log(process.cwd()); : D:\Nodejs\ \1\ECMA ( ) try{ process.chdir("/chdir"); }catch(ex) { console.log(ex); } Error: ENOENT: no such file or directory, uv_chdir ECMA chdir , try{ process.chdir("./chdir"); }catch(ex) { console.log(ex); } console.log(process.cwd()); D:\Nodejs\ \1\ECMA\chdir 6 config JSNode.js console.log(process.config);{target_defaults: variables: 7 connect Node.js Ipc channelIPC channel ,process.connect true. process.disconnect() process.connect false 8 cpuUsage cpu cpu ( ). user,system . ( ) user system , cpu console.log(process.cpuUsage()); { user: 296000, system: 46000 } 9 env config node.js . console.log(process.env); process.env.foo = "bar"; console.log(process.env.foo); bar process.env , console.log(typeof process.env); process.env.test = 1; console.log(typeof process.env.test ); : object string delete process.env process.env.TEST = 1; console.log(process.env.TEST); delete process.env.TEST; console.log(process.env.TEST); 1 undefined windows , process.env.TEST = 1; console.log(process.env.test); 1 10 execArgv Node.js ,node.js [] console.log(process.execArgv); : [] cmd , node --harmony 1.js --harmony ['--harmony'] process.argv process.execArgv node.js 11 execPath node.js console.log(process.execPath); C:\Program Files (x86)
odejs
ode.exe
12 exit([code]) code node.js . code , exit success 0, process.exitCode , node.js exit process.exit(1); : , 1 exit . ,process.exit() 。 ,node.js . process.exitCode process.exit --- process.exitCode, exit 13 exitCode , process.exit() exitCode 14 hrtime([time]) console.log(process.hrtime()); [ 161028, 255368780 ],[seconds,nanoseconds] ,nanoseconds var Time = process.hrtime(); console.log(process.hrtime(Time)); hrtime process.hrtime() : --- hrtime tuple Array, 1 " throw new TypeError('process.hrtime() only accepts an Array tuple'); process.hrtime() , 。 。 nextTick() callback nextTick , . nextTick callback ticks , I/0( ) function abc() { console.log('start function'); } console.log('start'); process.nextTick(function () { console.log("nextTick callback"); }); console.log('scheduled'); abc(); nextTick : , nextTick , nextTick callback . : nextTick I/O 15 pid PID setInterval(function () { console.log(process.pid); },10000); 10spid pid node.exe 16 platform , node.js console.log(process.platform); win32 17 release tarball URLs(tarball linux ) : 1 name: Node.js node 2 sourceUrl: .tar.gz URL, , Node-v8.4.0.tar.gz.( M) 3 headersUrl: .tar.gz URL, node.jsv8.4.0 400 kb 4 libUrl: node.lib URL, 。 。( windows : { name: 'node', sourceUrl: 'https://nodejs.org/download/release/v8.4.0/node-v8.4.0.tar.gz', headersUrl: 'https://nodejs.org/download/release/v8.4.0/node-v8.4.0-headers.tar.gz', libUrl: 'https://nodejs.org/download/release/v8.4.0/win-x64/node.lib' } 18 stdin stdin ,stdin , stdin.resume() , resume() 19 stdout stdout API : var num1,num2; process.stdout.write(" num1 :"); process.stdin.on("data",function (chunk) { if(!num1){ // num1 process.stdout.write('num1 :'+(typeof chunk)); num1 = Number(chunk); process.stdout.write(" num2 "); } else{ num2 = Number(chunk); process.stdout.write(' '+(num1+num2)); } }) data , chunk object : num1+num2 , num1 : num1 :4 num1 :object num2 6 10 4 4 4 ? else process.stdout.write('num1='+(num1)+'num2='+(num2)+'
');
, : num1 :23 num1 :object num2 20 num1=23num2=20 43 num1=23num2=0 23 num1=23num2=0 23 ?num2=0 ? : console.log(Number('
'));
, 。 ( ), Number('
')
0, num2=0 */