Been Googling for a while in order to find an answer to this question but I still can't get to find the matter in my code. I'm trying to make my very first Socket.io app that simply outputs a message to the console when a user connects.
Here's the error I get from Node.js:
And here is my source code:
var port = process.argv[2];
var express = require('express');
var app = express();
var path = require('path');
app.get('/', function(req, res) {
res.render('index.ejs');
})
.use(app.static(path.join(__dirname, '/public')));
var io = require('socket.io')(app.listen(port));
io.on('connection', function(socket) {
console.log('Someone connected');
});
console.log('Listening on port ' + port);
Been Googling for a while in order to find an answer to this question but I still can't get to find the matter in my code. I'm trying to make my very first Socket.io app that simply outputs a message to the console when a user connects.
Here's the error I get from Node.js:
And here is my source code:
var port = process.argv[2];
var express = require('express');
var app = express();
var path = require('path');
app.get('/', function(req, res) {
res.render('index.ejs');
})
.use(app.static(path.join(__dirname, '/public')));
var io = require('socket.io')(app.listen(port));
io.on('connection', function(socket) {
console.log('Someone connected');
});
console.log('Listening on port ' + port);
Thanks in advance for your advice!
Share Improve this question asked Apr 20, 2015 at 13:39 Drav'Drav' 1051 silver badge7 bronze badges 1-
2
Well,
app
doesn't have a methodstatic
. What did you expect that to do? Perhaps you meantexpress.static
? – deceze ♦ Commented Apr 20, 2015 at 13:41
2 Answers
Reset to default 12Change:
.use(app.static(path.join(__dirname, '/public')));
To:
.use(express.static(path.join(__dirname, '/public')));
I tried all the answers above, but didnt work for me. Then I tried to install express-static using "npm install -g express-static --save". And used in the code like below,
var pathComp= require("express-static");
app.use(pathComp(__dirname+"/client"));
Sharing this though its an old thread. For more reference visit, https://www.npmjs./package/express-static