Hola,
Estoy trabajando en mi archivo app.js en node.js y quiero hacer una solicitud http para obtener el contenido de una URL para poder usarlo como una cadena.
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;no funciona. Toda la aplicación dejará de funcionar y lo único que obtengo en la consola son 500 errores. ¿Qué es eso?
Gracias.