0
0
AstroConceptBeginner · 3 min read

@astrojs/node Adapter: What It Is and How It Works

The @astrojs/node adapter lets you run Astro projects as Node.js server applications. It connects Astro’s static and dynamic rendering to a Node.js environment, enabling server-side rendering and API routes.
⚙️

How It Works

The @astrojs/node adapter acts like a bridge between your Astro project and a Node.js server. Imagine Astro builds your website like a blueprint, and the adapter helps set up a Node.js server that can read this blueprint and serve your pages dynamically.

When you use this adapter, your Astro site can handle requests on the server, generate pages on the fly, and respond with HTML or data. This is useful for features like server-side rendering or APIs that need to run on a server instead of just static files.

💻

Example

This example shows how to configure the @astrojs/node adapter in your astro.config.mjs file to run your site on Node.js.

javascript
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: node(),
});
Output
Astro project configured to run as a Node.js server application.
🎯

When to Use

Use the @astrojs/node adapter when you want your Astro site to run on a Node.js server instead of just static hosting. This is helpful if you need server-side rendering, dynamic content, or API endpoints.

For example, if you want to build a blog that updates content dynamically or an app that fetches data on the server, this adapter lets you do that easily with Node.js.

Key Points

  • @astrojs/node enables running Astro projects as Node.js servers.
  • It supports server-side rendering and dynamic routes.
  • Ideal for apps needing backend logic or APIs.
  • Configured in astro.config.mjs with adapter: node().

Key Takeaways

The @astrojs/node adapter runs Astro projects on Node.js servers for dynamic content.
It enables server-side rendering and API routes in Astro apps.
Configure it in astro.config.mjs with adapter: node() and output: 'server'.
Use it when your site needs backend logic or dynamic page generation.
It bridges Astro’s static site features with Node.js server capabilities.