重学Node 0x0 Node Modules System

本文深入探讨了Node.js中模块的创建与加载过程,通过具体示例logger.js和app.js,详细讲解了如何定义和使用模块,展示了module.exports在模块导出中的作用。

module

console.log(module)

creating a module

//logger.js
const url = 'http://mylogger.io/log'
function log(message) {
  // send an HTTP request
  console.log(message)
}

module.exports.log = log

 Loading a Module

// app.js
const logger = require('./logger')
logger.log('hello')

Module Wrapper Function

Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 D:\newjobfile\codefile\newfilecode1\vuetestfile>npm run dev > vuetestfile@0.0.0 dev > vite 'vite' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 D:\newjobfile\codefile\newfilecode1\vuetestfile>npm install npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'execa@9.5.2', npm WARN EBADENGINE required: { node: '^18.19.0 || >=20.5.0' }, npm WARN EBADENGINE current: { node: 'v19.9.0', npm: '9.6.3' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'vite@6.2.2', npm WARN EBADENGINE required: { node: '^18.0.0 || ^20.0.0 || >=22.0.0' }, npm WARN EBADENGINE current: { node: 'v19.9.0', npm: '9.6.3' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@vitejs/plugin-vue@5.2.3', npm WARN EBADENGINE required: { node: '^18.0.0 || >=20.0.0' }, npm WARN EBADENGINE current: { node: 'v19.9.0', npm: '9.6.3' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'nanoid@5.1.5', npm WARN EBADENGINE required: { node: '^18 || >=20' }, npm WARN EBADENGINE current: { node: 'v19.9.0', npm: '9.6.3' } npm WARN EBADENGINE } npm ERR! code 1 npm ERR! path D:\newjobfile\codefile\newfilecode1\vuetestfile\node_modules\esbui ld npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node install.js npm ERR! node:internal/errors:867 npm ERR! const err = new Error(message); npm ERR! ^ npm ERR! npm ERR! Error: Command failed: D:\newjobfile\nodefile\node.exe D:\newjobfile\co defile\newfilecode1\vuetestfile\node_modules\esbuild\bin\esbuild --version npm ERR! Exception 0xc0000005 0x8 0x0 0x0 npm ERR! PC=0x0 npm ERR! npm ERR! runtime.asmstdcall(0x2a0700060009) npm ERR! runtime/sys_windows_amd64.s:76 +0x89 fp=0xdaf780 sp=0xdaf760 pc= 0xd8e69 npm ERR! rax 0x0 npm ERR! rbx 0xa3c780 npm ERR! rcx 0xa844a8 npm ERR! rdx 0x20 npm ERR! rdi 0x7fffffde000 npm ERR! rsi 0xdaf978 npm ERR! rbp 0xdaf8c0 npm ERR! rsp 0xdaf758 npm ERR! r8 0xa3c4a0 npm ERR! r9 0xa840ca npm ERR! r10 0xdba2e8 npm ERR! r11 0xc000004000 npm ERR! r12 0xdaf9c8 npm ERR! r13 0x0 npm ERR! r14 0xa3b660 npm ERR! r15 0x3 npm ERR! rip 0x0 npm ERR! rflags 0x10246 npm ERR! cs 0x33 npm ERR! fs 0x53 npm ERR! gs 0x2b npm ERR! node:child_process:924 npm ERR! throw err; npm ERR! ^ npm ERR! npm ERR! Error: Command failed: D:\newjobfile\codefile\newfilecode1\vuetestfile\ node_modules\@esbuild\win32-x64\esbuild.exe --version npm ERR! at checkExecSyncError (node:child_process:885:11) npm ERR! at Object.execFileSync (node:child_process:921:15) npm ERR! at Object.<anonymous> (D:\newjobfile\codefile\newfilecode1\vuetestf ile\node_modules\esbuild\bin\esbuild:221:28) npm ERR! at Module._compile (node:internal/modules/cjs/loader:1275:14) npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1329:10 ) npm ERR! at Module.load (node:internal/modules/cjs/loader:1133:32) npm ERR! at Module._load (node:internal/modules/cjs/loader:972:12) npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modul es/run_main:83:12) npm ERR! at node:internal/main/run_main_module:23:47 { npm ERR! status: 2, npm ERR! signal: null, npm ERR! output: [ null, null, null ], npm ERR! pid: 7396, npm ERR! stdout: null, npm ERR! stderr: null npm ERR! } npm ERR! npm ERR! Node.js v19.9.0 npm ERR! npm ERR! at checkExecSyncError (node:child_process:885:11) npm ERR! at Object.execFileSync (node:child_process:921:15) npm ERR! at validateBinaryVersion (D:\newjobfile\codefile\newfilecode1\vuete stfile\node_modules\esbuild\install.js:101:28) npm ERR! A complete log of this run can be found in: D:\newjobfile\nodefile\node _cache\_logs\2025-03-20T00_55_22_540Z-debug-0.log D:\newjobfile\codefile\newfilecode1\vuetestfile>
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值