How to read txt file from the Internet and write its contents to a variable on node.js

const http = require('http'); http.get('http://hexando.me/projects/fc/status.txt', (res) => { let data = String(); res.on('data', (chunk) => { data += chunk; }); }); fc.on('message', (message) => { if(message.content == "fc status") { message.reply(data) } }); 
  • new String() better to replace with '' - ThisMan
  • what fc ? and what is the difficulty? - ThisMan
  • 1. Move data beyond the closure limits. Otherwise, it will not be visible in fc.on ... 2. Add res.on('end' ... to the closure, otherwise how to understand that the data is all sucked in? @See documentation - Total Pusher

0