NodeJS - 无法初始化'假设'库

时间:2016-06-30 07:11:41

标签: node.js

我刚刚安装了“假设”库而没有任何问题并初始化它,但是一旦我启动了我的nodejs,我收到了这个错误:

$ node main.js

util.js:556   ctor.prototype = Object.create(superCtor.prototype, {
                          ^ TypeError: Object prototype may only be an Object or null
    at Function.create (native)
    at Object.exports.inherits (util.js:556:27)
    at Object.<anonymous> (/home/nagios/nodejs_local/node_modules/suppose/lib/suppose-process.js:101:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/nagios/nodejs_local/node_modules/suppose/lib/suppose.js:1:72)

我只是将其初始化为我的脚本标题,尚未使用。 这是完整的main.js文件:

    //this call required libraries
    /* node restful api main */
//----------------------------------------
var express = require('express');
var fs = require('fs');
var myapp = express();
var suppose = require('suppose');
var dbinterface = require('./routes/dbinterface');
var filemanager = require('./routes/filemanager');

//cors
myapp.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, body");
  next();
});

//FS APIs
myapp.post("/fs", filemanager.fsMan);

//This start http daemon on server
//-----------------------------------------
var server = myapp.listen(9999, function () {
                                var host = "10.135.235.16";
                                var port = server.address().port;
                                console.log("App start listen at address http://%s:%s.", host, port);
                            }
    );
//-----------------------------------------

这是filemanages.js文件

//this call required libraries
//---------------------------------------------------------------------------------------------
var exec = require('child_process').exec,
spawn = require('child_process').spawn,
express = require('express'),
x = require('suppose'),
command ,
output,
multer = require('multer'),
myexport = module.exports = {}; //make function available to external files


//multer object set----------------------------------------------------------------------------
var storage = multer.diskStorage({  
    destination: './uploads',
    filename: function(req,file,callback){
        callback(null, file.originalname)
    }
});
//APIs----------------------------------------------------------------------------------------
myexport.fsMan = function (req, res) {  
    var action = req.param('actionid');
    subaction="";
    command="";
    bigstring =  req.get("body"),
    values = bigstring.split("#");
//Command case--------------------------------------------------------------------------------
    switch (action) {
        case "getFileSize":
            command = 'ls -lrt ' + req.get("body") + " | awk  '{print $5}'";
            break;
        //--------------------------------------------------------------------------------
        case "copyFile":        
            sourfilepath=values[0], 
            destfilepath=values[1],
            command = 'cp ' + sourfilepath + " " + destfilepath;
            break;
        //--------------------------------------------------------------------------------      
        case "listFolderContent":
            command = " find " + req.get("body") + " -type f -exec ls -lrt {} \\; | awk '{print $5, \"#\", $9}'";
            break;
        //--------------------------------------------------------------------------------          
        case "cksumFiles":
            sourfilepath=values[0], 
            destfilepath=values[1],
            command = 'cksum ' + sourfilepath + " " + destfilepath + " | awk '{print $1 , \"#\"}'" ;
            break;
        //--------------------------------------------------------------------------------          
        default:
        err_handler(res, 501, ":Error on execute command:", ":parameter not valid");
        //--------------------------------------------------------------------------------      
    }
//--------------------------------------------------------------------------------------------- 
    console.log(command);

    if (/rm|vi|mv|more/g.test(command)) {
        err_handler(res, 501, ":Error on execute command:", ":command not allowed");
    } 
    else {
        exec(command, function(err, sto, ste) {
            if (command == null || command == "") {
                err_handler(res, 501, ":Error on execute command:", ":command cannot be null");
            }
            if (ste) {
                err_handler(res, 501, ":Error on execute command:", ste);
            }
            else {
                if (sto) {
                    res.end(JSON.stringify(sto));
                    }
                    else {
                        res.end("OK");
                    }
                }
        });
    }
}

//upload file ---------------------------------------------------------------------------------
myexport.upload = function(req,res) {
    var upload = multer({storage: storage}).single('lcl_upload');
    console.log(req.body);
    upload(req, res, function(err){
        if (err) {
            err_handler(res, 501, ":Error on upload file:", err);
            }
        else {
            res.end("OK");
        }
    });
}
//-------------------------------------------------------------------------------
function err_handler(res, err_code, err_message, err_detail){
    res.statusCode = err_code;
    res.end("KO" + err_message + err_detail);
}

如你所见,我使用了一个名为'x'的simpe变量,它使用了假设库。 如果我评论'x = require('suppose')语句,错误就会消失。 你们其中有人遇到同样的问题吗?

0 个答案:

没有答案