Created
March 3, 2021 16:19
-
-
Save deepakshrma/9a7c96671e7129c5a1246c8c34b65ea8 to your computer and use it in GitHub Desktop.
App for code share - Forget about JMeter, Start writing K6 scripts for Load Testing and Performance Monitoring
This file contains hidden or 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
// app/index.js | |
const fastify = require("fastify")({ logger: false }); | |
// Take port from env variable | |
const PORT = process.env.PORT || 3000; | |
// Create user database | |
const users = Array(100) | |
.fill(0) | |
.map((_, x) => ({ | |
name: `User_${x}`, | |
id: `ID_${x}`, | |
})); | |
// Declare a route | |
fastify.get("/users", async (request, reply) => { | |
reply.send(users); | |
}); | |
fastify.get("/user/:id", async (request, reply) => { | |
reply.send(users.find((x) => x.id == request.params["id"])); | |
}); | |
// Run the server! | |
const start = async () => { | |
try { | |
await fastify.listen(PORT, "0.0.0.0"); | |
} catch (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
}; | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment