简体   繁体   English

快递3文件上传:找不到模块“可读流”

[英]express 3 file upload: Cannot find module 'readable-stream'

I am following this tutorial on uploading a file. 我正在按照本教程上传文件。 I have an express 3 server with some config. 我有一个带有某些配置的Express 3服务器。 The express.multipart is giving me a Error: Cannot find module 'readable-stream' when I fire everything up express.multipart给我一个Error: Cannot find module 'readable-stream'当我启动所有内容时, Error: Cannot find module 'readable-stream'

server config: 服务器配置:

app.use(express.static(path.join(__dirname, 'public')));
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(express.multipart({ uploadDir: __dirname + '/uploads', limit: '50mb' }))

route: 路线:

app.post('/upload', function(req, res){
   console.log(req.files.file.name + ' has been uploaded')
   res.send(200)
})

html markup: html标记:

<form action='/upload' method='POST' enctype='multipart/form-data'>
    <input type='file' name='file'>
    <input type='submit' class='btn btn-default' value='Upload'>
</form>

I am using node v0.10.29 and npm 1.4.14 . 我正在使用node v0.10.29npm 1.4.14 What's the minimum express config for handling a file upload? 处理文件上传的最低Express配置是多少? Or is this a problem with my environment? 还是我的环境有问题?

Fixed it. 修复。

express config: 表达配置:

app.use(express.static(path.join(__dirname, 'public')));
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(express.bodyParser({ uploadDir: path.join(__dirname + '/uploads'), keepExtensions: true }))

route: 路线:

app.post('/upload', function(req, res){
    var fileName = req.files.fileName.name,
        filePath = req.files.fileName.path;

    console.log(fileName + ' added to uploads')

    // Do something with file here:
    // - save metadata to database
    // - upload file to S3 bucket

    // remove file from our server
    fs.unlink(filePath, function(err){
        console.log(fileName + ' has been deleted!')
    })
    res.redirect('/')
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM