日期:2014-05-16  浏览次数:20354 次

NodeJS: 一行代码引发的杯具

这几天有点儿小空,寻思着看看Node JS 方面的东东。

在网上东搜搜西搜搜,找到如下网站:

http://www.nodebeginner.org/index-zh-cn.html

?

主题是node 入门。

?

于是乎就照着上面的代码敲下来, 一路行来倒是没有怎么遇到困难。

?

唯独最后在引入fs 模块和 formidable模块尝试完成文件上传功能时,出问题了。

?

报错如下:

?

?fs.renameSync(files.upload.path, "C:/sap/java/nodejs/examples/testUpload/test.png"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ ? ? ? ? ? ? ? ? ? ??

TypeError: Cannot read property 'path' of undefined

? ? at c:\sap\java\nodejs\examples\hello\requestHandlers.js:30:30

? ? at IncomingForm.<anonymous> (c:\sap\java\nodejs\examples\hello\node_modules\

formidable\lib\incoming_form.js:89:9)

? ? at IncomingForm.EventEmitter.emit (events.js:95:17)

? ? at IncomingForm._error (c:\sap\java\nodejs\examples\hello\node_modules\formi

dable\lib\incoming_form.js:272:8)

? ? at IncomingMessage.<anonymous> (c:\sap\java\nodejs\examples\hello\node_modul

es\formidable\lib\incoming_form.js:119:14)

? ? at IncomingMessage.EventEmitter.emit (events.js:92:17)

? ? at _stream_readable.js:920:16

? ? at process._tickCallback (node.js:415:13)

?