Created
February 5, 2021 22:38
-
-
Save osdevisnot/36547ad6eb84503a92f564e0de079e6c to your computer and use it in GitHub Desktop.
esbuild-fastify-starter
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
node_modules | |
dist | |
yarn.lock |
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
#!/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) |
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
{ | |
"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" | |
} | |
} |
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 fastify = require('fastify')({ logger: true }) | |
fastify.get('/hello', async (request, reply) => { | |
return { hello: 'world' } | |
}) | |
fastify.listen(3000) |
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 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