Squash Tomato Journal — November 12, 2017–11:30
Published in
1 min readNov 14, 2017
- Organized the future functionality of family lists
- Searched for realtime solutions for my user interface. I wanted users of the same list to see the changes another was making as soon as they changed them. I came upon WebSockets. Although I’d like to use the barebones WebSockets’ API, I’m using Socket.io for speed since I’m up against a deadline!
- Went through the Socket.io tutorial — Someone is clearly more intelligent than I am 😆
- Began to integrate Socket.io into Squash Tomato on a git feature branch (separated from master, which controls what’s running on my server)
const mongoose = require('mongoose');// import env variablesrequire('dotenv').config({ path: 'variables.env' });// connect to our database and handle bad connectionsmongoose.connect(process.env.LOCAL_DATABASE);mongoose.Promise = global.Promise; // tell mongoose to use es6 promisesmongoose.connection.on('error', (err) => { console.log(`Shit! Fuck! It's not working! 😡😡😡 → ${err.message}`);});// Les do it, bitches!require('./models/User');require('./models/SharedList');const http = require('http');const app = require('./app');const server = http.createServer(app);const io = require('socket.io').listen(server);server.listen(process.env.LOCAL_PORT || 27017, () => { console.log(`Express is running 👉🏻 ${process.env.LOCAL_PORT || 27017}`);});io.on('connection', (socket) => { socket.emit('news', { hello: 'world' });});