TypeError:app.get不是函数 [英] TypeError: app.get is not a function

查看:184
本文介绍了TypeError:app.get不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在原型中使用express

I'm trying to use express in a prototype

function ioServer() {

}

module.exports = ioServer;

ioServer.prototype.start = function() {
    var app       = require('express')
    var http      = require('http').Server(app)
    var io        = require('socket.io')(http)

    app.get('/', function(req, res) {
        var outPut = ""
        res.sendFile(__dirname + './client/index.html')
    })

    http.listen(3000, function(port) {
        console.log('Listening on port, ' + 3000)
    })
}

但是当我使用它时会抛出错误 TypeError:app.get不是函数当我删除原型部件时,它可以工作。

But when I use it It throws the error TypeError: app.get is not a function When I remove the prototype part it works.

推荐答案

您的 app 应该是快递的实例。

Your app should be an instance of express.

例如,你可以这样包括:

For example, you could include it like this:

var app = require('express')();

这篇关于TypeError:app.get不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆