What is the purpose of the Node.js adapter in Astro for self-hosting?
The Node.js adapter allows Astro projects to run on a Node.js server, enabling self-hosting by handling server-side rendering and serving static assets.
Click to reveal answer
beginner
How do you install the Node.js adapter for Astro?
You install it using npm or yarn with the command: npm install @astrojs/node or yarn add @astrojs/node.
Click to reveal answer
beginner
Which file do you modify to configure the Node.js adapter in an Astro project?
You modify the <code>astro.config.mjs</code> file to import and add the Node.js adapter in the <code>integrations</code> array.
Click to reveal answer
intermediate
What command do you run to start the Astro project with the Node.js adapter for self-hosting?
You run npm run build to build the project, then node ./dist/server/entry.mjs to start the server.
Click to reveal answer
intermediate
Why is the Node.js adapter useful compared to static hosting in Astro?
It supports dynamic server-side rendering and APIs, allowing more interactive and personalized content than static hosting.
Click to reveal answer
What does the Node.js adapter for Astro enable?
ARunning Astro projects on a Node.js server
BDeploying Astro projects only on static hosts
CConverting Astro projects to React apps
DAutomatically updating Astro dependencies
✗ Incorrect
The Node.js adapter enables running Astro projects on a Node.js server for self-hosting.
Which command installs the Node.js adapter for Astro?
Anpm install astro-node-adapter
Bnpm install astro-server
Cnpm install node-astro
Dnpm install @astrojs/node
✗ Incorrect
The correct package name is @astrojs/node.
Where do you add the Node.js adapter in an Astro project?
AIn the main HTML file
BIn the package.json scripts section
CIn the astro.config.mjs file under integrations
DIn the node_modules folder
✗ Incorrect
Adapters are configured in astro.config.mjs under the integrations array.
What is the typical command to start the server after building with the Node.js adapter?
Anpm start
Bnode ./dist/server/entry.mjs
Castro dev
Dnpm run serve
✗ Incorrect
After building, you run the server entry file with Node.js directly.
What advantage does the Node.js adapter provide over static hosting?
ASupports dynamic server-side rendering
BFaster static file delivery
CSimplifies CSS styling
DAutomatically generates SEO tags
✗ Incorrect
The Node.js adapter allows dynamic server-side rendering, unlike static hosting.
Explain how to set up the Node.js adapter for self-hosting in an Astro project.
Think about installation, configuration, build, and run steps.
You got /5 concepts.
Describe the benefits of using the Node.js adapter for self-hosting compared to static hosting in Astro.
Consider what dynamic features static hosting lacks.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Node.js adapter in Astro?
easy
A. To convert Astro sites into mobile apps automatically
B. To run Astro sites on your own server using Node.js
C. To deploy Astro sites only on static hosting platforms
D. To generate CSS styles for Astro components
Solution
Step 1: Understand the role of the Node.js adapter
The Node.js adapter allows Astro sites to be run on a Node.js server, enabling self-hosting.
Step 2: Compare options with this purpose
Only To run Astro sites on your own server using Node.js correctly describes running Astro sites on your own server using Node.js.
Final Answer:
To run Astro sites on your own server using Node.js -> Option B
Quick Check:
Node.js adapter = run Astro on own server [OK]
Hint: Node.js adapter = self-host Astro site with Node.js [OK]
Common Mistakes:
Thinking adapter only deploys static sites
Confusing adapter with mobile app tools
Assuming adapter generates CSS
2. Which configuration correctly sets up Astro to use the Node.js adapter for self-hosting?
easy
A. { output: 'static', adapter: static() }
B. { output: 'static', adapter: node() }
C. { output: 'server', adapter: static() }
D. { output: 'server', adapter: node() }
Solution
Step 1: Identify required output setting for Node.js adapter
Node.js adapter requires output: 'server' to enable server-side rendering.
Hint: Node.js adapter always needs output set to 'server' [OK]
Common Mistakes:
Using output 'static' with Node.js adapter
Mixing static adapter with server output
Forgetting to call node() function
3. Given this Astro config snippet, what happens when you run node ./dist/server/entry.mjs after building?
{
output: 'server',
adapter: node()
}
medium
A. The site runs on a Node.js server allowing dynamic requests
B. The site builds static files only, no server runs
C. An error occurs because adapter is missing
D. The site runs but only serves static HTML files
Solution
Step 1: Understand build output with Node.js adapter
With output: 'server' and adapter: node(), Astro builds a server-ready app.
Step 2: Running node ./dist/server/entry.mjs starts the Node.js server
This command launches the server to handle dynamic requests.
Final Answer:
The site runs on a Node.js server allowing dynamic requests -> Option A
Quick Check:
Node.js adapter + output 'server' = dynamic server run [OK]
Hint: Run entry.mjs with Node to start server for dynamic site [OK]
Common Mistakes:
Assuming static files only are built
Expecting error without adapter
Thinking server serves only static HTML
4. You set output: 'server' but forgot to add adapter: node() in your Astro config. What happens when you try to build?
medium
A. Build produces static files ignoring server output
B. Build succeeds but site cannot run on Node.js server
C. Build fails with an error about missing adapter
D. Build succeeds and site runs normally on Node.js
Solution
Step 1: Check requirement for server output
When output: 'server' is set, an adapter like node() is required to handle server build.
Step 2: Missing adapter causes build error
Without adapter: node(), the build process fails with an error indicating the missing adapter.
Final Answer:
Build fails with an error about missing adapter -> Option C
Quick Check:
Server output needs adapter, else build error [OK]
Hint: Server output requires adapter; missing it causes build error [OK]
Common Mistakes:
Assuming build succeeds without adapter
Thinking static files are generated instead
Believing site runs normally without adapter
5. You want to self-host an Astro site with dynamic server rendering and also serve some static assets efficiently. Which setup correctly achieves this using the Node.js adapter?
hard
A. Set output: 'server', use adapter: node(), and place static files in public/ folder
B. Set output: 'static', use adapter: node(), and serve static files from src/
C. Set output: 'server', use adapter: static(), and place static files in public/
D. Set output: 'static', use adapter: static(), and place static files in public/
Solution
Step 1: Choose output and adapter for dynamic server rendering
Dynamic server rendering requires output: 'server' and adapter: node().
Step 2: Serve static assets efficiently
Static files should be placed in the public/ folder to be served directly by the server.
Final Answer:
Set output 'server', adapter node(), and static files in public/ folder -> Option A