var express = require("express");
var app = express();
var server = require("http").createServer(app);
var io = require("socket.io")(server);
var port = process.env.PORT || 3000;
const fs = require("fs");
app.get("/", (req, res) => {
var q = url.parse(req.url, true);
var filename = `.${q.pathname}`;
fs.readFile(filename, (err, data) => {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
return res.end("404 Not Found");
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
});
});
error: TypeError: app.get is not a function
.
So what I am trying to do is allow clients to request an profile picture from the server.
So when client changes profile picture, base64 is converted into png image that will be saved on server, then I want allow client to use url to request that image for profile picture. How I can do that?
socket.on("account-change-avatar", (data) => {
for (var i = 0; i < Database.storage.accounts.length; i++) {
if (Database.storage.accounts[i].id == data.id) {
var base64 = data.url.replace(/^data:image\/png;base64,/, "");
fs.appendFile(`${Database.storage.accounts[i].id}.png`, base64, "base64", (err) => {
if (err) throw err;
Database.storage.accounts[i].avatar = "URL HERE";
socket.emit("account-refresh", "URL HERE");
});
break;
}
}
});