const http = require("http")
console.log(global.process)
process {
title: 'node',
version: 'v8.7.0',
moduleLoadList:
[ 'Binding contextify',
'Binding natives',
'Binding config',
'NativeModule events',
'Binding async_wrap',
'Binding icu',
'NativeModule util',
'NativeModule internal/errors',
'NativeModule internal/encoding',
'NativeModule internal/util',
'Binding util',
'Binding constants',
'Binding buffer',
'NativeModule buffer',
'NativeModule internal/buffer',
'Binding uv',
'NativeModule internal/process',
'NativeModule internal/process/warning',
'NativeModule internal/process/next_tick',
'NativeModule async_hooks',
'NativeModule internal/process/promises',
'NativeModule internal/process/stdio',
'NativeModule timers',
'Binding timer_wrap',
'NativeModule internal/linkedlist',
'NativeModule assert',
'NativeModule module',
'NativeModule internal/module',
'NativeModule internal/url',
'NativeModule internal/querystring',
'NativeModule querystring',
'Binding url',
'NativeModule vm',
'NativeModule fs',
'NativeModule path',
'Binding fs',
'NativeModule stream',
'NativeModule internal/streams/legacy',
'NativeModule _stream_readable',
'NativeModule internal/streams/BufferList',
'NativeModule internal/streams/destroy',
'NativeModule _stream_writable',
'NativeModule _stream_duplex',
'NativeModule _stream_transform',
'NativeModule _stream_passthrough',
'Binding fs_event_wrap',
'NativeModule internal/fs',
'NativeModule internal/loader/Loader',
'NativeModule url',
'NativeModule internal/loader/ModuleWrap',
'Binding module_wrap',
'NativeModule internal/loader/ModuleMap',
'NativeModule internal/loader/ModuleJob',
'NativeModule internal/safe_globals',
'NativeModule internal/loader/resolveRequestUrl',
'NativeModule internal/loader/search',
'NativeModule console',
'Binding tty_wrap',
'NativeModule tty',
'NativeModule net',
'NativeModule internal/net',
'Binding cares_wrap',
'Binding tcp_wrap',
'Binding pipe_wrap',
'Binding stream_wrap',
'NativeModule dns',
'NativeModule readline',
'NativeModule string_decoder',
'NativeModule internal/readline',
'Binding inspector',
'Binding performance',
'NativeModule perf_hooks',
'NativeModule internal/inspector_async_hook',
'NativeModule http',
'NativeModule _http_agent',
'NativeModule _http_client',
'Binding http_parser',
'NativeModule _http_common',
'NativeModule internal/freelist',
'NativeModule internal/http',
'NativeModule _http_incoming',
'NativeModule _http_outgoing',
'NativeModule _http_server' ],
versions: { http_parser: '2.7.0',
node: '8.7.0',
v8: '6.1.534.42',
uv: '1.15.0',
zlib: '1.2.11',
ares: '1.10.1-DEV',
modules: '57',
nghttp2: '1.25.0',
openssl: '1.0.2l',
icu: '59.1',
unicode: '9.0',
cldr: '31.0.1',
tz: '2017b' },
arch: 'x64',
platform: 'darwin',
release:
{ name: 'node',
sourceUrl: 'https://nodejs.org/download/release/v8.7.0/node-v8.7.0.tar.gz',
headersUrl: 'https://nodejs.org/download/release/v8.7.0/node-v8.7.0-headers.tar.gz' },
argv:
[ '/usr/local/bin/node',
'/Users/apple/Desktop/test/comjs/index.js' ],
execArgv: [],
env:
{ NVM_RC_VERSION: '',
TERM_PROGRAM: 'Apple_Terminal',
NVM_CD_FLAGS: '',
SHELL: '/bin/bash',
TERM: 'xterm-256color',
TMPDIR: '/var/folders/vm/n4myfnyx0gxc0pt2vgqgqhzc0000gn/T/',
Apple_PubSub_Socket_Render: '/private/tmp/com.apple.launchd.ch6yYRuIxm/Render',
TERM_PROGRAM_VERSION: '388.1.1',
OLDPWD: '/Users/apple/Desktop/test',
TERM_SESSION_ID: '4F4E6FB2-133A-45E6-8F26-EBFF7A2D5695',
NVM_DIR: '/Users/apple/.nvm',
USER: 'apple',
SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.MWhBvOCKwO/Listeners',
__CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x0',
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',
PWD: '/Users/apple/Desktop/test/comjs',
JAVA_HOME: '/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home',
XPC_FLAGS: '0x0',
XPC_SERVICE_NAME: '0',
M2_HOME: '/Users/apple/Downloads/apache-maven-3.5.3',
SHLVL: '1',
HOME: '/Users/apple',
LOGNAME: 'apple',
LC_CTYPE: 'UTF-8',
GOPATH: '/Users/apple/go/src/calcproj',
DISPLAY: '/private/tmp/com.apple.launchd.mQOTg3abGU/org.macosforge.xquartz:0',
SECURITYSESSIONID: '186a6',
_: '/usr/local/bin/node' },
pid: 71393,
features:
{ debug: false,
uv: true,
ipv6: true,
tls_npn: true,
tls_alpn: true,
tls_sni: true,
tls_ocsp: true,
tls: true },
_needImmediateCallback: false,
execPath: '/usr/local/bin/node',
debugPort: 9229,
_startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
_stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
_getActiveRequests: [Function: _getActiveRequests],
_getActiveHandles: [Function: _getActiveHandles],
reallyExit: [Function: reallyExit],
abort: [Function: abort],
chdir: [Function: chdir],
cwd: [Function: cwd],
umask: [Function: umask],
getuid: [Function: getuid],
geteuid: [Function: geteuid],
setuid: [Function: setuid],
seteuid: [Function: seteuid],
setgid: [Function: setgid],
setegid: [Function: setegid],
getgid: [Function: getgid],
getegid: [Function: getegid],
getgroups: [Function: getgroups],
setgroups: [Function: setgroups],
initgroups: [Function: initgroups],
_kill: [Function: _kill],
_debugProcess: [Function: _debugProcess],
_debugPause: [Function: _debugPause],
_debugEnd: [Function: _debugEnd],
hrtime: [Function: hrtime],
cpuUsage: [Function: cpuUsage],
dlopen: [Function: dlopen],
uptime: [Function: uptime],
memoryUsage: [Function: memoryUsage],
binding: [Function: binding],
_linkedBinding: [Function: _linkedBinding],
_setupDomainUse: [Function: _setupDomainUse],
_events:
{ warning: [Function],
SIGWINCH: [ [Function], [Function] ],
newListener: [Function],
removeListener: [Function] },
_rawDebug: [Function],
_eventsCount: 4,
domain: null,
_maxListeners: undefined,
_fatalException: [Function],
_exiting: false,
assert: [Function],
config:
{ target_defaults:
{ cflags: [],
default_configuration: 'Release',
defines: [],
include_dirs: [],
libraries: [] },
variables:
{ asan: 0,
coverage: false,
debug_devtools: 'node',
debug_http2: false,
debug_nghttp2: false,
force_dynamic_crt: 0,
host_arch: 'x64',
icu_data_file: 'icudt59l.dat',
icu_data_in: '../../deps/icu-small/source/data/in/icudt59l.dat',
icu_endianness: 'l',
icu_gyp_path: 'tools/icu/icu-generic.gyp',
icu_locales: 'en,root',
icu_path: 'deps/icu-small',
icu_small: true,
icu_ver_major: '59',
llvm_version: 0,
node_byteorder: 'little',
node_enable_d8: false,
node_enable_v8_vtunejit: false,
node_install_npm: true,
node_module_version: 57,
node_no_browser_globals: false,
node_prefix: '/usr/local',
node_release_urlbase: 'https://nodejs.org/download/release/',
node_shared: false,
node_shared_cares: false,
node_shared_http_parser: false,
node_shared_libuv: false,
node_shared_openssl: false,
node_shared_zlib: false,
node_tag: '',
node_use_bundled_v8: true,
node_use_dtrace: true,
node_use_etw: false,
node_use_lttng: false,
node_use_openssl: true,
node_use_perfctr: false,
node_use_v8_platform: true,
node_without_node_options: false,
openssl_fips: '',
openssl_no_asm: 0,
shlib_suffix: '57.dylib',
target_arch: 'x64',
uv_parent_path: '/deps/uv/',
uv_use_dtrace: true,
v8_enable_gdbjit: 0,
v8_enable_i18n_support: 1,
v8_enable_inspector: 1,
v8_no_strict_aliasing: 1,
v8_optimized_debug: 0,
v8_promise_internal_field_count: 1,
v8_random_seed: 0,
v8_trace_maps: 0,
v8_use_snapshot: true,
want_separate_host_toolset: 0,
xcode_version: '7.0' } },
emitWarning: [Function],
nextTick: [Function: nextTick],
_tickCallback: [Function: _tickCallback],
_tickDomainCallback: [Function: _tickDomainCallback],
stdout: [Getter],
stderr: [Getter],
stdin: [Getter],
openStdin: [Function],
exit: [Function],
kill: [Function],
argv0: 'node',
mainModule:
Module {
id: '.',
exports: {},
parent: null,
filename: '/Users/apple/Desktop/test/comjs/index.js',
loaded: false,
children: [],
paths:
[ '/Users/apple/Desktop/test/comjs/node_modules',
'/Users/apple/Desktop/test/node_modules',
'/Users/apple/Desktop/node_modules',
'/Users/apple/node_modules',
'/Users/node_modules',
'/node_modules' ] } }
node环境中,放弃了将变量放在window 变量中的做法
const http = require("http")
var a = "asdf"
console.log(global.process === process) //true
console.log(global.a === a) //false
const {argv,argv0,execArgv,execPath} = process;
console.log("argv:")
argv.forEach(item =>{
console.log(item)
})
console.log("argv0: ",argv0)
console.log("execArgv: ",execArgv)
console.log("execPath: ",execPath)
$node --inspect index.js test -g:
argv:
/usr/local/bin/node
/Users/apple/Desktop/test/comjs/index.js
test
-g
argv0: node
execArgv: [ '--inspect' ]
execPath: /usr/local/bin/node
setImmediate 与 proces.nextTick
setImmediate(() => {
console.log("it is setImmediate")
})
process.nextTick(()=>{
console.log('it is nextTick')
})
proces.nextTick会把回调函数放在消息队列的最前端