Now, let's create a Koa app with the Backpack default configuration (without creating the Backpack config file) as follows:
- Install Koa via npm:
$ npm i koa
- Use /src/ as the Backpack default entry directory and create an entry file in this directory with minimal code in Koa style as follows:
// src/index.js
const Koa = require('koa')
const app = new Koa()
app.use(async ctx => {
ctx.body = 'Hello World'
})
app.listen(3000)
- Run the Koa app in development mode:
$ npm run dev
You should see Hello World on the screen when browsing the app on a browser at 127.0.0.1:3000. If you have been using Express to create your Node.js apps, you can see that Koa is an alternative that can be used to do the same thing with neater code. Next, let's learn what a Koa context is and how cascading works in Koa in the following sections.