Created
November 12, 2020 06:56
-
-
Save mayankchoubey/ee7ea1e8b959030b405b8621d862c0d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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