0
I’m creating a simple chat that switches simultaneous messages between 2 browsers, using Node.js with socket.io, but for some reason, my project can’t identify my socket.io.js within the project. And yes, I lowered 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 %>
What’s the mistake? You made it
npm install?– Sergio
did yes, it accuses 404 in socket.io.js file, but I installed socket.io
– Michel Henriq