Skip to content

Instantly share code, notes, and snippets.

@tarusharora
Created December 22, 2018 21:33
Show Gist options
  • Save tarusharora/abc887a625876273dc9e18f0365c7d64 to your computer and use it in GitHub Desktop.
Save tarusharora/abc887a625876273dc9e18f0365c7d64 to your computer and use it in GitHub Desktop.
node-api-boilerplate
// import dependencies from npm
const Fastify = require('fastify');
const path = require('path');
const AutoLoad = require('fastify-autoload');
const uuidv4 = require('uuid/v4');
// create request ids
const createRequestId = () => uuidv4();
// create the server
const server = Fastify({
ignoreTrailingSlash: true,
logger: {
genReqId: createRequestId,
level: 'info'
}
});
/* the following line is going to be removed in favor of
simple multiple imports provided by
fastify-autoload
*/
server.get('/', async function (request, reply) {
return { hello: "World" }
})
// start the server
server.listen(9000, (err) => {
if (err) {
server.log.error(err);
console.log(err);
process.exit(1);
}
server.log.info('Server Started');
});
@irfanbaigse
Copy link

https://www.fastify.io/docs/latest/Server/#gen-request-id

// create the server
const server = Fastify({
    ignoreTrailingSlash: true,
    genReqId: createRequestId,
    logger: {
        level: 'info'
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment