Run a node app in "dev mode"
npm install @softnetics/dev-serverA simple utility to run a node app in "dev mode"
- Load .env files and restart on their changes
- Manually restart by pressing r
``javascript
// dev.js
import { createDevServer } from '@softnetics/dev-server'
import chokidar from 'chokidar'
const { start, stop, restart } = createDevServer({
command: 'node src/server.js',
})
start()
// watch for changes in src
chokidar.watch('./src').on('all', () => restart())
`
Then run the dev server
`bash`
node dev.js
In a project that requires a bundling process, you can use tsup watch mode to automatically rebuild the project on source change, and start the dev server on successful build.
When a source file is changed, the dev server will automatically stop before tsup restarts the build process.
`javascript
// dev.js
import { tsupDevServer } from '@softnetics/dev-server'
import { build } from 'tsup'
build({
entry: ['src/server.ts'],
watch: true,
onSuccess: tsupDevServer({
command: 'node dist/server.js',
}),
})
``