This repo shows an example of how to integrate Astro with an existing Express website.
This will help you when you have an existing Express Website and whant to migrate it to Astro. Astro does not need Express.
Reference: https://docs.astro.build/en/guides/integrations-guide/node/
Follow the commits to see the progress.
npx express-generator astro-node-express
cd astro-node-express
npm install
npm install nodemon -D
npm install @astrojs/node
Create astro.config.mjs with:
import { defineConfig } from 'astro/config'
import node from '@astrojs/node'
export default defineConfig({
output: 'server',
adapter: node({
mode: 'middleware',
}),
})
# this generates /dist folder
npx astro build
// app.js
const setupAstroMiddleware = require('./lib/setupAstroMiddleware')
/** Astro pages/middlewares */
setupAstroMiddleware('/', path.join(__dirname, 'dist'), app)
Add package.json scripts:
"scripts": {
"start": "npm run astro:build && node ./bin/www",
"dev": "DEBUG=astro-node-express:* nodemon --exec \"npm run astro:build && node ./bin/www\" -e js,mjs,cjs,json,astro,ts,tsx --ignore dist/",
"astro:build": "astro check && astro build --silent"
},
- Add Astro initial pages/styles/layout
- Add Astro island examples
- Add Astro hot reload on changes