1. const http = require("http")
  2. console.log(global.process)
  1. process {
  2. title: 'node',
  3. version: 'v8.7.0',
  4. moduleLoadList:
  5. [ 'Binding contextify',
  6. 'Binding natives',
  7. 'Binding config',
  8. 'NativeModule events',
  9. 'Binding async_wrap',
  10. 'Binding icu',
  11. 'NativeModule util',
  12. 'NativeModule internal/errors',
  13. 'NativeModule internal/encoding',
  14. 'NativeModule internal/util',
  15. 'Binding util',
  16. 'Binding constants',
  17. 'Binding buffer',
  18. 'NativeModule buffer',
  19. 'NativeModule internal/buffer',
  20. 'Binding uv',
  21. 'NativeModule internal/process',
  22. 'NativeModule internal/process/warning',
  23. 'NativeModule internal/process/next_tick',
  24. 'NativeModule async_hooks',
  25. 'NativeModule internal/process/promises',
  26. 'NativeModule internal/process/stdio',
  27. 'NativeModule timers',
  28. 'Binding timer_wrap',
  29. 'NativeModule internal/linkedlist',
  30. 'NativeModule assert',
  31. 'NativeModule module',
  32. 'NativeModule internal/module',
  33. 'NativeModule internal/url',
  34. 'NativeModule internal/querystring',
  35. 'NativeModule querystring',
  36. 'Binding url',
  37. 'NativeModule vm',
  38. 'NativeModule fs',
  39. 'NativeModule path',
  40. 'Binding fs',
  41. 'NativeModule stream',
  42. 'NativeModule internal/streams/legacy',
  43. 'NativeModule _stream_readable',
  44. 'NativeModule internal/streams/BufferList',
  45. 'NativeModule internal/streams/destroy',
  46. 'NativeModule _stream_writable',
  47. 'NativeModule _stream_duplex',
  48. 'NativeModule _stream_transform',
  49. 'NativeModule _stream_passthrough',
  50. 'Binding fs_event_wrap',
  51. 'NativeModule internal/fs',
  52. 'NativeModule internal/loader/Loader',
  53. 'NativeModule url',
  54. 'NativeModule internal/loader/ModuleWrap',
  55. 'Binding module_wrap',
  56. 'NativeModule internal/loader/ModuleMap',
  57. 'NativeModule internal/loader/ModuleJob',
  58. 'NativeModule internal/safe_globals',
  59. 'NativeModule internal/loader/resolveRequestUrl',
  60. 'NativeModule internal/loader/search',
  61. 'NativeModule console',
  62. 'Binding tty_wrap',
  63. 'NativeModule tty',
  64. 'NativeModule net',
  65. 'NativeModule internal/net',
  66. 'Binding cares_wrap',
  67. 'Binding tcp_wrap',
  68. 'Binding pipe_wrap',
  69. 'Binding stream_wrap',
  70. 'NativeModule dns',
  71. 'NativeModule readline',
  72. 'NativeModule string_decoder',
  73. 'NativeModule internal/readline',
  74. 'Binding inspector',
  75. 'Binding performance',
  76. 'NativeModule perf_hooks',
  77. 'NativeModule internal/inspector_async_hook',
  78. 'NativeModule http',
  79. 'NativeModule _http_agent',
  80. 'NativeModule _http_client',
  81. 'Binding http_parser',
  82. 'NativeModule _http_common',
  83. 'NativeModule internal/freelist',
  84. 'NativeModule internal/http',
  85. 'NativeModule _http_incoming',
  86. 'NativeModule _http_outgoing',
  87. 'NativeModule _http_server' ],
  88. versions: { http_parser: '2.7.0',
  89. node: '8.7.0',
  90. v8: '6.1.534.42',
  91. uv: '1.15.0',
  92. zlib: '1.2.11',
  93. ares: '1.10.1-DEV',
  94. modules: '57',
  95. nghttp2: '1.25.0',
  96. openssl: '1.0.2l',
  97. icu: '59.1',
  98. unicode: '9.0',
  99. cldr: '31.0.1',
  100. tz: '2017b' },
  101. arch: 'x64',
  102. platform: 'darwin',
  103. release:
  104. { name: 'node',
  105. sourceUrl: 'https://nodejs.org/download/release/v8.7.0/node-v8.7.0.tar.gz',
  106. headersUrl: 'https://nodejs.org/download/release/v8.7.0/node-v8.7.0-headers.tar.gz' },
  107. argv:
  108. [ '/usr/local/bin/node',
  109. '/Users/apple/Desktop/test/comjs/index.js' ],
  110. execArgv: [],
  111. env:
  112. { NVM_RC_VERSION: '',
  113. TERM_PROGRAM: 'Apple_Terminal',
  114. NVM_CD_FLAGS: '',
  115. SHELL: '/bin/bash',
  116. TERM: 'xterm-256color',
  117. TMPDIR: '/var/folders/vm/n4myfnyx0gxc0pt2vgqgqhzc0000gn/T/',
  118. Apple_PubSub_Socket_Render: '/private/tmp/com.apple.launchd.ch6yYRuIxm/Render',
  119. TERM_PROGRAM_VERSION: '388.1.1',
  120. OLDPWD: '/Users/apple/Desktop/test',
  121. TERM_SESSION_ID: '4F4E6FB2-133A-45E6-8F26-EBFF7A2D5695',
  122. NVM_DIR: '/Users/apple/.nvm',
  123. USER: 'apple',
  124. SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.MWhBvOCKwO/Listeners',
  125. __CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x0',
  126. PATH: '/Users/apple/Desktop/bts:/Users/apple/Downloads/geckodriver:/Users/apple/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/Users/apple/Downloads/apache-maven-3.5.3/bin',
  127. PWD: '/Users/apple/Desktop/test/comjs',
  128. JAVA_HOME: '/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home',
  129. XPC_FLAGS: '0x0',
  130. XPC_SERVICE_NAME: '0',
  131. M2_HOME: '/Users/apple/Downloads/apache-maven-3.5.3',
  132. SHLVL: '1',
  133. HOME: '/Users/apple',
  134. LOGNAME: 'apple',
  135. LC_CTYPE: 'UTF-8',
  136. GOPATH: '/Users/apple/go/src/calcproj',
  137. DISPLAY: '/private/tmp/com.apple.launchd.mQOTg3abGU/org.macosforge.xquartz:0',
  138. SECURITYSESSIONID: '186a6',
  139. _: '/usr/local/bin/node' },
  140. pid: 71393,
  141. features:
  142. { debug: false,
  143. uv: true,
  144. ipv6: true,
  145. tls_npn: true,
  146. tls_alpn: true,
  147. tls_sni: true,
  148. tls_ocsp: true,
  149. tls: true },
  150. _needImmediateCallback: false,
  151. execPath: '/usr/local/bin/node',
  152. debugPort: 9229,
  153. _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
  154. _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
  155. _getActiveRequests: [Function: _getActiveRequests],
  156. _getActiveHandles: [Function: _getActiveHandles],
  157. reallyExit: [Function: reallyExit],
  158. abort: [Function: abort],
  159. chdir: [Function: chdir],
  160. cwd: [Function: cwd],
  161. umask: [Function: umask],
  162. getuid: [Function: getuid],
  163. geteuid: [Function: geteuid],
  164. setuid: [Function: setuid],
  165. seteuid: [Function: seteuid],
  166. setgid: [Function: setgid],
  167. setegid: [Function: setegid],
  168. getgid: [Function: getgid],
  169. getegid: [Function: getegid],
  170. getgroups: [Function: getgroups],
  171. setgroups: [Function: setgroups],
  172. initgroups: [Function: initgroups],
  173. _kill: [Function: _kill],
  174. _debugProcess: [Function: _debugProcess],
  175. _debugPause: [Function: _debugPause],
  176. _debugEnd: [Function: _debugEnd],
  177. hrtime: [Function: hrtime],
  178. cpuUsage: [Function: cpuUsage],
  179. dlopen: [Function: dlopen],
  180. uptime: [Function: uptime],
  181. memoryUsage: [Function: memoryUsage],
  182. binding: [Function: binding],
  183. _linkedBinding: [Function: _linkedBinding],
  184. _setupDomainUse: [Function: _setupDomainUse],
  185. _events:
  186. { warning: [Function],
  187. SIGWINCH: [ [Function], [Function] ],
  188. newListener: [Function],
  189. removeListener: [Function] },
  190. _rawDebug: [Function],
  191. _eventsCount: 4,
  192. domain: null,
  193. _maxListeners: undefined,
  194. _fatalException: [Function],
  195. _exiting: false,
  196. assert: [Function],
  197. config:
  198. { target_defaults:
  199. { cflags: [],
  200. default_configuration: 'Release',
  201. defines: [],
  202. include_dirs: [],
  203. libraries: [] },
  204. variables:
  205. { asan: 0,
  206. coverage: false,
  207. debug_devtools: 'node',
  208. debug_http2: false,
  209. debug_nghttp2: false,
  210. force_dynamic_crt: 0,
  211. host_arch: 'x64',
  212. icu_data_file: 'icudt59l.dat',
  213. icu_data_in: '../../deps/icu-small/source/data/in/icudt59l.dat',
  214. icu_endianness: 'l',
  215. icu_gyp_path: 'tools/icu/icu-generic.gyp',
  216. icu_locales: 'en,root',
  217. icu_path: 'deps/icu-small',
  218. icu_small: true,
  219. icu_ver_major: '59',
  220. llvm_version: 0,
  221. node_byteorder: 'little',
  222. node_enable_d8: false,
  223. node_enable_v8_vtunejit: false,
  224. node_install_npm: true,
  225. node_module_version: 57,
  226. node_no_browser_globals: false,
  227. node_prefix: '/usr/local',
  228. node_release_urlbase: 'https://nodejs.org/download/release/',
  229. node_shared: false,
  230. node_shared_cares: false,
  231. node_shared_http_parser: false,
  232. node_shared_libuv: false,
  233. node_shared_openssl: false,
  234. node_shared_zlib: false,
  235. node_tag: '',
  236. node_use_bundled_v8: true,
  237. node_use_dtrace: true,
  238. node_use_etw: false,
  239. node_use_lttng: false,
  240. node_use_openssl: true,
  241. node_use_perfctr: false,
  242. node_use_v8_platform: true,
  243. node_without_node_options: false,
  244. openssl_fips: '',
  245. openssl_no_asm: 0,
  246. shlib_suffix: '57.dylib',
  247. target_arch: 'x64',
  248. uv_parent_path: '/deps/uv/',
  249. uv_use_dtrace: true,
  250. v8_enable_gdbjit: 0,
  251. v8_enable_i18n_support: 1,
  252. v8_enable_inspector: 1,
  253. v8_no_strict_aliasing: 1,
  254. v8_optimized_debug: 0,
  255. v8_promise_internal_field_count: 1,
  256. v8_random_seed: 0,
  257. v8_trace_maps: 0,
  258. v8_use_snapshot: true,
  259. want_separate_host_toolset: 0,
  260. xcode_version: '7.0' } },
  261. emitWarning: [Function],
  262. nextTick: [Function: nextTick],
  263. _tickCallback: [Function: _tickCallback],
  264. _tickDomainCallback: [Function: _tickDomainCallback],
  265. stdout: [Getter],
  266. stderr: [Getter],
  267. stdin: [Getter],
  268. openStdin: [Function],
  269. exit: [Function],
  270. kill: [Function],
  271. argv0: 'node',
  272. mainModule:
  273. Module {
  274. id: '.',
  275. exports: {},
  276. parent: null,
  277. filename: '/Users/apple/Desktop/test/comjs/index.js',
  278. loaded: false,
  279. children: [],
  280. paths:
  281. [ '/Users/apple/Desktop/test/comjs/node_modules',
  282. '/Users/apple/Desktop/test/node_modules',
  283. '/Users/apple/Desktop/node_modules',
  284. '/Users/apple/node_modules',
  285. '/Users/node_modules',
  286. '/node_modules' ] } }

node环境中,放弃了将变量放在window 变量中的做法

  1. const http = require("http")
  2. var a = "asdf"
  3. console.log(global.process === process) //true
  4. console.log(global.a === a) //false
  1. const {argv,argv0,execArgv,execPath} = process;
  2. console.log("argv:")
  3. argv.forEach(item =>{
  4. console.log(item)
  5. })
  6. console.log("argv0: ",argv0)
  7. console.log("execArgv: ",execArgv)
  8. console.log("execPath: ",execPath)

$node --inspect index.js test -g:

  1. argv:
  2. /usr/local/bin/node
  3. /Users/apple/Desktop/test/comjs/index.js
  4. test
  5. -g
  6. argv0: node
  7. execArgv: [ '--inspect' ]
  8. execPath: /usr/local/bin/node

setImmediate 与 proces.nextTick

  1. setImmediate(() => {
  2. console.log("it is setImmediate")
  3. })
  4. process.nextTick(()=>{
  5. console.log('it is nextTick')
  6. })

proces.nextTick会把回调函数放在消息队列的最前端