suma-db
Version:
A Brazilian database that supports JSON(JavaScript Object Notation)
28 lines (17 loc) • 725 B
JavaScript
const http = require("http");
const loadWeb = (path='db', all, port) => {
let porta = process.env.PORT || port || gerarRandom(1000, 9999);
let server = http.createServer(async (req, res) => {
if (req.url === `/${path}` && req.method === "GET") {
res.writeHead(200, { "Content-Type": "application/json" });
res.write(JSON.stringify(all, null, 4));
res.end();
}
})
server.listen(porta, () => null)
return { content: JSON.stringify(all, null, 4), url: `http://localhost:${porta}/${path}`, link: `http://localhost:${porta}/${path}`, port: porta }
}
module.exports = loadWeb
function gerarRandom(min, max) {
return ~~(Math.random() * (max - min) + 1)
}