Currently, I have a route configured to fetch the weather data for a specific city using the openweathermap API
Here is the code snippet from my index.js file:
var express = require("express"),
router = express.Router();
var weather = require("openweather-apis");
router.get("/weather", function(req, res){
weather.setCity('Miami');
weather.setAPPID(appID);
weather.getAllWeather(function(err, allWeather){
res.json({allWeather: allWeather});
});
});
Now, I am looking to implement a websocket connection on this route so that I can receive real-time updates whenever there is a change in the data and show it to the users. Here's what I have tried:
From my index.ejs file:
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js"></script>
<script>
var socket = io('http://localhost:3000/weather');
socket.on('connect', function(){});
socket.on('event', function(data){
// do something
});
socket.on('disconnect', function(){});
</script>
Unfortunately, I keep encountering errors while attempting this setup. If anyone has insights on where I might be going wrong, I would greatly appreciate the assistance!
The error message I am receiving is as follows:
index.js:83 GET http://localhost:3000/socket.io/?EIO=3&transport=polling&t=Mzd4Dpj 404 (Not Found)