'TypeError: app.get is not a function
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)
})
}
But when I use it It throws the error TypeError: app.get is not a function
When I remove the prototype part it works.
Solution 1:[1]
Your app
should be an instance of express.
For example, you could include it like this:
var app = require('express')();
Solution 2:[2]
when you require express you forgot to place ( ) try this
const app = require('express')();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | svens |
Solution 2 | Muhammad Awais |