codeforgeek / socket-notification Goto Github PK
View Code? Open in Web Editor NEWReal-time notification System using Socket.io and ExpressJS
Home Page: https://codeforgeek.com/real-time-notification-system-using-socket-io/
Real-time notification System using Socket.io and ExpressJS
Home Page: https://codeforgeek.com/real-time-notification-system-using-socket-io/
This is not an issue per-se but just a question on the variation of how to handle the notification from the server.
Here is my case:
I am inserting a record using mysql upon which I need to send notification to other connected users.
This is the code:
app.js
var http = require('http');
var io = require('socket.io')(http);
io.on('connection', function(socket){
console.log('a user connected');
socket.on('new-rec-created', function(){
//io.emit('a new housekeeping was requested'); // for all
socket.broadcast.emit('notify everyone'); // for all except me
});
});
route.js
var http = require('http');
var io = require('socket.io')(http);
connectionPool.getConnection(function(err, connection){
if(err) {
winston.log('debug', '------------------------------------ Error: ' + err);
connection.release();
return;
}
connection.query(queryString, function(err, rows){
if (err) {
winston.log('debug', '------------------------------------ Error: ' + err);
}
connection.release();
socket.emit('new-rec-created');
});
});
my public side main.js file
$(document).ready(function(){
var socket = io();
socket.on('notify everyone',function(){
notifyMe(); //the js desktop notification code
});
.
.
});
Couple of issues I am facing:
<script src="/socket.io/socket.io.js"></script>
it kept giving me 404 not found error. So finally I had to use the cdn <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.1/socket.io.js"></script>
I dont understand what I am doing wrong. The weird thing is when I start the server the console.log('a user connected') under io.on('connection') is not printed. Any suggestions or advice?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.