TypeError:object不是Node.js函数

 山野木每子 发布于 2023-02-11 20:59

我在Lynda.com上做Node.js基本训练......

在视频之后,我在终端中收到此错误.

"TypeError:object不是函数"

node_modules /航班/ index.js

var count = 0,
    destinations = [];

var Flight = function () {
        this.data = {
        number : null,
        origin: null,
        destination: null,
        departs: null,
        arrives: null,
        actualDepart: null,
        actualArrive: null
    };

    this.fill = function (info) {
            for(var prop in this.data) {
        if(this.data[prop] !== 'undefined') {
            this.data[prop] = info[prop];
        }
    }
    };

        this.triggerDepart = function () {
            this.data.actualDepart = Date.now();
        };
        this.triggerArrive = function () {
            this.data.actualArrive = Date.now();
        };
        this.getInformation = function () {
            return this.data;
        };
};  

exports.create = function (info) {
    var instance = new Flight();    
    instance.fill(info);

    count++;
    if(destinations.indexOf(info['destination']) <0) {
        destinations.push(info['destination']);
    }
    return instance;
};

exports.getCount = function() {
    return count;
};

exports.getDestinations = function () {
    return destinations;
};

路线/ index.js

/*
 * GET home page.
 */

 var flight= require('../node_modules/flight');
 var flight1 = flight({
     number :1,
     origin: 'LAX',
     destination : 'DCA',
     departs: '9AM',
     arrives:'4PM'
 });

 var flight2 = flight({
     number : 2,
     origin: 'LAX',
     destination : 'PDX',
     departs: '10AM',
     arrives: '12PM'
 });

exports.flight1 = function(req, res){
  res.json(flight1.getInformation());
};

exports.flight2 = function(req, res){
  res.json(flight2.getInformation());
};

app.js

/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' === app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);

app.get('/flight1', routes.Flight1);

app.get('/flight2', routes.Flight2);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

不确定如何排除故障.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有