Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Created November 12, 2020 06:56
Show Gist options
  • Save mayankchoubey/ee7ea1e8b959030b405b8621d862c0d5 to your computer and use it in GitHub Desktop.
Save mayankchoubey/ee7ea1e8b959030b405b8621d862c0d5 to your computer and use it in GitHub Desktop.
import { serve } from "https://deno.land/std/http/server.ts";
import { v1 } from "https://deno.land/std/uuid/mod.ts";
const s = serve({ port: 3000 });
const decoder = new TextDecoder();
for await (const req of s) {
const body=JSON.parse(decoder.decode(await Deno.readAll(req.body)));
const uuids=[];
for(let i=0; i<body.requiredUuids; i++)
uuids.push(v1.generate());
req.respond({ body: JSON.stringify(uuids)});
}
const http = require('http');
const { v1: uuidv1 } = require('uuid');
var server = http.createServer(function(request, response) {
let data = '';
request.on('data', chunk => data += chunk);
request.on('end', () => {
const body=JSON.parse(data);
const uuids=[];
for(let i=0; i<body.requiredUuids; i++)
uuids.push(uuidv1());
response.writeHead(200, {"Content-Type": "application/json"});
response.end(JSON.stringify(uuids));
});
});
server.listen(process.env.PORT||3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment