配置模块缺少属性

时间:2015-03-24 15:19:40

标签: node.js express cloudinary

我有一个cloudinary配置模块:

var express = require('express');
var app = express();
var cloudinary = require('cloudinary');
var config = require('./config.json')[app.get('env')];

module.exports = function(){
    cloudinary.config({
        cloud_name: config.cloudinary_cloud_name,
        api_key: config.cloudinary_api_key,
        api_secret: config.cloudinary_api_secret
    });

    return cloudinary;
};

我用它:

var cloudinary = require('../config/cloudinary');

cloudinary.uploader.upload(file.path, function (result) {

我收到了这个错误:

Cannot read property 'upload' of undefined

1 个答案:

答案 0 :(得分:2)

执行require('../config/cloudinary')时,它不执行该功能。您可以像这样使用它:

var cloudinary = require('../config/cloudinary')();

cloudinary.uploader.upload(file.path, function (result) {