Hi,
I am working on my app.js file on node.js and I want to make a http request to get the contents from an URL so I can use it as a string.
const app = require("express")();
const httpServer = require("http").createServer(app);
const io = require("socket.io")(httpServer);
app.get('/myappt', (req, res) => {
res.sendFile('index.html');
});
let numUsers = 0;
var options = {
host: 'http://example.net',
path: '/test.txt',
port: 80
};
callback = function(response) {
var str = '';
//another chunk of data has been received, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been received, so we just print it out here
response.on('end', function () {
username = str;
});
};
httpserver.request(options, callback).end();
io.on('connection', (socket) => {
let addedUser = false;
// when the client emits 'add user', this listens and executes
socket.on('add user', (username) => {
if (addedUser) return;
// we store the username in the socket session for this client
socket.username = username;
its not working. The whole app will stop working at all and the only thing I get on the console is 500 errors. What is that?
Thank you.