Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@astrojs/node

Package Overview
Dependencies
Maintainers
4
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astrojs/node

Deploy your site to a Node.js server

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

@astrojs/node

An experimental static-side rendering adapter for use with Node.js servers.

In your astro.config.mjs use:

import nodejs from '@astrojs/node';

export default {
  adapter: nodejs()
}

After performing a build there will be a dist/server/entry.mjs module that works like a middleware function. You can use with any framework that supports the Node request and response objects. For example, with Express you can do:

import express from 'express';
import { handler as ssrHandler } from './dist/server/entry.mjs';

const app = express();
app.use(ssrHandler);

app.listen(8080);

Using http

This adapter does not require you use Express and can work with even the http and https modules. The adapter does following the Expression convention of calling a function when either

  • A route is not found for the request.
  • There was an error rendering.

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);

FAQs

Package last updated on 25 Mar 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc