How to connect to a socket using EJS, node and express?

I'm trying to build a chat app with socket.io, passport.js, ejs and express. I have the authentication working but for some reason my socket connection isn't working. This is my index.js file. The socket connection is handled down at the bottom. I followed the socket.io docs.

const app = require('express')();
const authRoutes = require('./routes/auth-routes');
const profileRoutes = require('./routes/profile-routes');
const passportSetup = require('./config/passport-setup');
const mongoose = require('mongoose');
const keys = require('./config/keys');
const cookieSession = require('cookie-session');
const passport = require('passport');
const passSocket = require('passport.socketio');
const server = require('http').Server(app);
const io = require('socket.io')(server);

//set up view engine
app.set('view engine', 'ejs');

app.use(cookieSession({
    maxAge: 24 * 60 * 60 * 1000,
    keys: [keys.session.cookieKey]
}));

//initialize passport
app.use(passport.initialize());
app.use(passport.session());

//set up routes
app.use('/auth', authRoutes);
app.use('/profile', profileRoutes);

//create home route
app.get('/', (req, res) => {
    res.render('home', {user: req.user});
});

app.get('/rooms', (req, res) => {
    //list existing rooms
});

app.post('/rooms', (req, res) => {
    //create a new chatroom
});

app.get('/room/{roomID}/subscribe', (req, res) => {
    //subscribe to this room
});

app.get('/room/{roomID}/messages', (req, res) => {
    //list messages of this room
});

app.post('/room/{roomID}/messages', (req, res) => {
    //post a message to this room
});

app.listen(3000, () => {
    console.log('App now listening for requests on port 3000');
});

server.listen(8080, () =>{
    console.log('Waiting for socket connection on port 8080...');
});

// Connect to mongodb
mongoose.connect(keys.mongodb.dbURI, { useNewUrlParser: true }, () => {
    console.log('Connected to MongoDB');
});

io.on('connection', (socket) => {
    console.log('Socket initialized...');
    socket.emit('prof', {name: 'jon'});
    socket.on('other', (data) => {
        console.log(data);
    })
});

and here is the profile.ejs file. This is the page that is loaded when a user is authenticated. I even tried switching the script src to a socket.io cdn but that still didn't work.

<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <title>Profile</title>
    <style>
        body{
            font-family: arial;
            margin: 0;
        }
        nav{
            background: #ff5353;
            padding: 20px 10px;
        }
        nav ul{
            max-width: 960px;
            margin: 0 auto;
            padding: 0;
        }
        nav li{
            list-style-type: none;
            display: inline-block;
            margin: 0 10px 0;
        }
        nav a{
            color: #fff;
            font-size: 18px;
            background: rgba(255,255,255,0.2);
            text-decoration: none;
            padding: 10px;
            display: block;
        }
        main,header{
            max-width: 960px;
            margin: 30px auto;
            padding: 0 10px;
            color: #333;
        }
    </style>
    </head>
    <body>
        <nav>
            <ul>
                <% if (user) { %>
                <li><a href="/auth/logout">Logout</a></li>
                <% } else { %>
                <li><a href="/auth/login">Login</a></li>
                <% } %>
                <li><a href="/">Homepage</a></li>
                <li><a href="/profile">Profile</a></li>
            </ul>
        </nav>
        <header>
            <h1>Welcome back to Smartchat, <%= user.username%></h1>
        </header>
        <main>
        </main>
    </body>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect('https://127.0.0.1:8080');
        if(socket != undefined){
            console.log('Connected to socket...');
        }
        socket.on('prof', (data) => {
            console.log(data);
            socket.emit('other', {socket: 'connected'});
        })
    </script>
</html>

This is my first time working with websockets so any help would be appreciated. How do I connect to the socket?