![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@astrojs/node
Advanced tools
Deploy your site to a Node.js server
This adapter allows Astro to deploy your SSR site to Node targets.
If you're using Astro as a static site builder—its behavior out of the box—you don't need an adapter.
If you wish to use server-side rendering (SSR), Astro requires an adapter that matches your deployment runtime.
Node is a JavaScript runtime for server-side code. Frameworks like Express are built on top of it and make it easier to write server applications in Node. This adapter provides access to Node's API and creates a script to run your Astro project that can be utilized in Node applications.
Add the Node adapter to enable SSR in your Astro project with the following astro add
command. This will install the adapter and make the appropriate changes to your astro.config.mjs
file in one step.
# Using NPM
npx astro add node
# Using Yarn
yarn astro add node
# Using PNPM
pnpm astro add node
If you prefer to install the adapter manually instead, complete the following two steps:
Install the Node adapter to your project’s dependencies using your preferred package manager. If you’re using npm or aren’t sure, run this in the terminal:
npm install @astrojs/node
Add two new lines to your astro.config.mjs
project configuration file.
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
output: 'server',
adapter: node(),
});
After performing a build there will be a dist/server/entry.mjs
module that exposes a handler
function. This works like a middleware function: it can handle incoming requests and respond accordingly.
You can use this handler
with any framework that supports the Node request
and response
objects.
For example, with Express:
import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';
const app = express();
app.use(express.static('dist/client/'))
app.use(ssrHandler);
app.listen(8080);
http
This output script does not require you use Express and can work with even the built-in http
and https
node modules. The handler does follow the convention calling an error function when either
You can use these to implement your own 404 behavior like so:
import http from 'http';
import { handler as ssrHandler } from './dist/server/entry.mjs';
http.createServer(function(req, res) {
ssrHandler(req, res, err => {
if(err) {
res.writeHead(500);
res.end(err.toString());
} else {
// Serve your static assets here maybe?
// 404?
res.writeHead(404);
res.end();
}
});
}).listen(8080);
This adapter does not expose any configuration options.
For help, check out the #support
channel on Discord. Our friendly Support Squad members are here to help!
You can also check our Astro Integration Documentation for more on integrations.
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR!
See CHANGELOG.md for a history of changes to this integration.
FAQs
Deploy your site to a Node.js server
The npm package @astrojs/node receives a total of 23,828 weekly downloads. As such, @astrojs/node popularity was classified as popular.
We found that @astrojs/node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.