Answer the question
In order to leave comments, you need to log in
How to organize the work of Vue-cli, Express and socket.io?
Good afternoon.
I am developing an application on Vue (using cli). Needed a back.
Chose Express and socket.io on nodeJS.
I just don't understand how to run it. There is a dev server that raises Vue-cli, there is a server that I raise through nodeJS.
The problem is, I can't seem to get it to work. When a client connects to a node server, I send it an index.html file from /public.
server.js
const PORT = 3000;
console.log( `server started, port: ${PORT}\n` );
const express = require('express');
const app = express();
const server = require('http').createServer( app );
server.listen( PORT );
const io = require( 'socket.io' ).listen( server );
app.get( '/', function( req, res ){
res.sendFile( __dirname + '/public/index.html' );
});
io.sockets.on( 'connection', socket =>{
connections.push( socket );
console.log( `users (connected): ${connections.length}\n` );
socket.on( 'disconnect', data =>{
connections.splice( connections.indexOf( socket ), 1 );
console.log( `users (disconnected): ${connections.length}\n` );
});
io.sockets.emit( 'test', 'test' );
});
<html lang="ru"><head>
<meta charset="utf-8">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>title</title>
</head>
<body cz-shortcut-listen="true">
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body></html>
Answer the question
In order to leave comments, you need to log in
I don't understand anything either
There is a dev server that raises Vue-cli, respectively, vue-cli hangs it on
localhost:8000
, or what is there? I do not rememberthere is a server that I raise through nodeJS
When the client connects to the node server, then I send him the index.html file from /public
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question