Created
June 25, 2019 20:31
-
-
Save jonschlinkert/ca697ad2a8c57c92ad391026a943657f to your computer and use it in GitHub Desktop.
Simple, cross-platform way to open the browser upon starting an app.
This file contains hidden or 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 cp = require('child_process'); | |
const Koa = require('koa'); | |
const app = new Koa(); | |
const cmds = { linux: 'xdg-open', win32: 'start chrome', darwin: 'open' }; | |
const open = cmds[process.platform]; | |
const PORT = 3000; | |
// response | |
app.use(ctx => { | |
ctx.body = 'Hello Koa'; | |
}); | |
cp.execSync(`${open} http://localhost:${PORT}/`); | |
app.listen(PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment