Creating an Express app with Backpack can be as easy as implementing the following steps:
- Install Express via npm:
$ npm i express
- Add build and start scripts after the dev script in the package.json file:
// package.json
"scripts": {
"dev": "backpack",
"build": "backpack build",
"start": "cross-env NODE_ENV=production node build/main.js"
}
- Create the Backpack config file and use /server/ as the entry folder of your app, just as we have walked you through in the previous section:
// backpack.config.js
module.exports = {
webpack: (config, options, webpack) => {
config.entry.main = './server/index.js'
return config
}
}
- Create a simple route with a 'Hello World' message:
// server/index.js
import express from 'express'
const app = express()
const port = 3000
app.get('/', (req, res) =>
res.send(&apos...