我启动服务器成功,但客户端连接有错误node.js



我成功启动服务器,但客户端连接出错https://jsfiddle.net/m9wvm4nu/3/(css中是文件debuglog)如果您不需要节点中的代码,这里有文件调试日志。我不知道发生了什么

 0 info it worked if it ends with ok
    1 verbose cli [ 'C:\nodejs\node.exe',
    1 verbose cli   'C:\nodejs\node_modules\npm\bin\npm-cli.js',
    1 verbose cli   'start' ]
    2 info using npm@3.3.12
    3 info using node@v5.1.0
    4 verbose run-script [ 'prestart', 'start', 'poststart' ]
    5 info lifecycle simple-website@1.0.0~prestart: simple-website@1.0.0
    6 silly lifecycle simple-website@1.0.0~prestart: no script for prestart, continuing
    7 info lifecycle simple-website@1.0.0~start: simple-website@1.0.0
    8 verbose lifecycle simple-website@1.0.0~start: unsafe-perm in lifecycle true
    9 verbose lifecycle simple-website@1.0.0~start: PATH: C:nodejsnode_modulesnpmbinnode-gyp-bin;D:1-PROJECTsimple-websitenode_modules.bin;C:UsersMyPCbin;C:UsersMyPCAppDataLocalProgramsGitmingw64bin;C:UsersMyPCAppDataLocalProgramsGitusrlocalbin;C:UsersMyPCAppDataLocalProgramsGitusrbin;C:UsersMyPCAppDataLocalProgramsGitusrbin;C:UsersMyPCAppDataLocalProgramsGitmingw64bin;C:UsersMyPCAppDataLocalProgramsGitusrbin;C:UsersMyPCbin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)SkypePhone;C:nodejs;C:UsersMyPCAppDataLocalatombin;C:UsersMyPCAppDataLocal.meteor;C:UsersMyPCAppDataRoamingnpm;C:UsersMyPCAppDataLocalProgramsGitcmd;C:UsersMyPCAppDataLocalProgramsGitmingw64bin;C:UsersMyPCAppDataLocalProgramsGitusrbin;C:UsersMyPCAppDataLocalProgramsGitusrbinvendor_perl;C:UsersMyPCAppDataLocalProgramsGitusrbincore_perl
    10 verbose lifecycle simple-website@1.0.0~start: CWD: D:1-PROJECTsimple-website
    11 silly lifecycle simple-website@1.0.0~start: Args: [ '/d /s /c', 'node server.js' ]
    12 silly lifecycle simple-website@1.0.0~start: Returned: code: 1  signal: null
    13 info lifecycle simple-website@1.0.0~start: Failed to exec start script
    14 verbose stack Error: simple-website@1.0.0 start: `node server.js`
    14 verbose stack Exit status 1
    14 verbose stack     at EventEmitter.<anonymous> (C:nodejsnode_modulesnpmlibutilslifecycle.js:232:16)
    14 verbose stack     at emitTwo (events.js:87:13)
    14 verbose stack     at EventEmitter.emit (events.js:172:7)
    14 verbose stack     at ChildProcess.<anonymous> (C:nodejsnode_modulesnpmlibutilsspawn.js:24:14)
    14 verbose stack     at emitTwo (events.js:87:13)
    14 verbose stack     at ChildProcess.emit (events.js:172:7)
    14 verbose stack     at maybeClose (internal/child_process.js:818:16)
    14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
    15 verbose pkgid simple-website@1.0.0
    16 verbose cwd D:1-PROJECTsimple-website
    17 error Windows_NT 10.0.10240
    18 error argv "C:\nodejs\node.exe" "C:\nodejs\node_modules\npm\bin\npm-cli.js" "start"
    19 error node v5.1.0
    20 error npm  v3.3.12
    21 error code ELIFECYCLE
    22 error simple-website@1.0.0 start: `node server.js`
    22 error Exit status 1
    23 error Failed at the simple-website@1.0.0 start script 'node server.js'.
    23 error Make sure you have the latest version of node.js and npm installed.
    23 error If you do, this is most likely a problem with the simple-website package,
    23 error not with npm itself.
    23 error Tell the author that this fails on your system:
    23 error     node server.js
    23 error You can get their info via:
    23 error     npm owner ls simple-website
    23 error There is likely additional logging output above.
    24 verbose exit [ 1, true ]

我不确定是什么导致了您的特定错误,但这是您的脚本中的一个问题:

var mineType = mineType[path.extname(fileName).split(".").reverse()[0]];
res.writeHead(200, {'content-Type': mineType});

mineType表和局部变量不能使用相同的变量名。将本地变量更改为其他变量名:

var type = mineType[path.extname(fileName).split(".").reverse()[0]];
res.writeHead(200, {'content-Type': type});

最新更新