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

时间:2015-11-30 07:22:21

标签: node.js

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

 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:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\1-PROJECT\simple-website\node_modules\.bin;C:\Users\MyPC\bin;C:\Users\MyPC\AppData\Local\Programs\Git\mingw64\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\local\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin;C:\Users\MyPC\AppData\Local\Programs\Git\mingw64\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin;C:\Users\MyPC\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Skype\Phone;C:\nodejs;C:\Users\MyPC\AppData\Local\atom\bin;C:\Users\MyPC\AppData\Local\.meteor;C:\Users\MyPC\AppData\Roaming\npm;C:\Users\MyPC\AppData\Local\Programs\Git\cmd;C:\Users\MyPC\AppData\Local\Programs\Git\mingw64\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin\vendor_perl;C:\Users\MyPC\AppData\Local\Programs\Git\usr\bin\core_perl
    10 verbose lifecycle simple-website@1.0.0~start: CWD: D:\1-PROJECT\simple-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:\nodejs\node_modules\npm\lib\utils\lifecycle.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:\nodejs\node_modules\npm\lib\utils\spawn.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-PROJECT\simple-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 ]

1 个答案:

答案 0 :(得分:0)

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

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});