Chapter 6: code samples

This commit is contained in:
Beth Griggs
2020-05-30 19:33:25 +01:00
parent 4f825bdac3
commit b43bf2c378
398 changed files with 6049 additions and 53643 deletions
+27
View File
@@ -0,0 +1,27 @@
const fastify = require("fastify")();
const PORT = process.env.PORT || 3000;
// fastify.get("/", async (request, reply) => {
// return { message: "Hello world!" };
// });
fastify.route({
method: "GET",
url: "/",
handler: async (request, reply) => {
reply.send({ message: "Hello world!" });
},
});
const startServer = async () => {
try {
await fastify.listen(PORT);
console.log(`server listening on ${fastify.server.address().port}`);
} catch (err) {
console.error(err);
process.exit(1);
}
};
startServer();