Skip to content

Instantly share code, notes, and snippets.

@osdevisnot
Created February 5, 2021 22:38
Show Gist options
  • Save osdevisnot/36547ad6eb84503a92f564e0de079e6c to your computer and use it in GitHub Desktop.
Save osdevisnot/36547ad6eb84503a92f564e0de079e6c to your computer and use it in GitHub Desktop.
esbuild-fastify-starter
node_modules
dist
yarn.lock
#!/usr/bin/env node
let server,
isDev = process.argv[2] === 'start',
{ spawn } = require('child_process'),
onRebuild = () => {
if (isDev) {
if (server) server.kill('SIGINT')
server = spawn('node', ['dist/server.js'], { stdio: 'inherit' })
}
}
require('esbuild')
.build({
entryPoints: ['src/server.js'],
outdir: 'dist',
platform: 'node',
bundle: true,
sourcemap: true,
watch: isDev && { onRebuild },
})
.finally(onRebuild)
{
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "node ./esbuild.js build",
"start": "node ./esbuild.js start"
},
"dependencies": {
"fastify": "^3.11.0"
},
"devDependencies": {
"esbuild": "^0.8.42"
}
}
const fastify = require('fastify')({ logger: true })
fastify.get('/hello', async (request, reply) => {
return { hello: 'world' }
})
fastify.listen(3000)
const fastify = require('fastify')({ logger: true })
fastify.get('/hello', async (request, reply) => {
return { hello: 'world' }
})
fastify.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment