404 socket.io.js with express on node.js

0

I am creating a simple chat, which exchanges simultaneous messages between 2 browsers, using node.js with socket.io, but for some reason, my project can not identify my socket.io.js inside the project. And yes, I downloaded the socket.io.

My app.js is this way.

const KEY = 'ntalk.sid',
    SECRET = 'ntalk';
var express = require('express'),
    load = require('express-load'),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    expressSession = require('express-session'),
    methodOverride = require('method-override'),
    error = require('./middlewares/error'),
    app = express(),
    server = require('http').Server(app),
    io = require('socket.io')(server),
    cookie = cookieParser(SECRET),
    store = new expressSession.MemoryStore();
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(cookie);
app.use(expressSession({
    secret: SECRET,
    name: KEY,
    resave: true,
    saveUninitialized: true,
    store: store
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(methodOverride('_method'));
app.use(express.static(__dirname + '/public'));
load('models')
    .then('controllers')
    .then('routes')
    .into(app);
load('sockets')
    .into(io);
app.listen(3000, function() {
    console.log("Ntalk no ar.");
});

and this is my file where I call my script.js

<% include ../header %>
<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io('http://localhost:3000');
    socket.on('send-client', function(msg) {
        var chat = document.getElementById('chat');
        chat.innerHTML += msg;
    });
    var enviar = function() {
        var msg = document.getElementById('msg');
        socket.emit('send-server', msg.value);
    };

</script>
<header>
    <h2>Ntalk - Chat</h2>
</header>
<section>
    <pre id="chat"></pre>
    <input type="text" id="msg" placeholder="Mensagem">
    <input type="button" onclick="enviar();" value="Enviar">
</section>

<% include ../exit %>
<% include ../footer %>
    
asked by anonymous 28.06.2016 / 19:30

0 answers