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

@sveltejs/adapter-node

Package Overview
Dependencies
Maintainers
4
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/adapter-node

[Adapter](https://kit.svelte.dev/docs/adapters) for SvelteKit apps that generates a standalone Node server.

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
103K
decreased by-25.51%
Maintainers
4
Weekly downloads
 
Created

What is @sveltejs/adapter-node?

@sveltejs/adapter-node is an adapter for SvelteKit that allows you to build and deploy your SvelteKit application as a Node.js server. This adapter is useful for deploying SvelteKit applications to environments where Node.js is available, such as traditional hosting providers or custom server setups.

What are @sveltejs/adapter-node's main functionalities?

Basic Setup

This code demonstrates how to configure the @sveltejs/adapter-node in your SvelteKit project. The `adapter` function is imported and used in the `kit` configuration. You can specify the output directory, whether to precompress files, and environment variables for the host and port.

```javascript
// svelte.config.js
import adapter from '@sveltejs/adapter-node';

export default {
  kit: {
    adapter: adapter({
      out: 'build',
      precompress: false,
      env: {
        host: 'HOST',
        port: 'PORT'
      }
    })
  }
};
```

Custom Server

This code demonstrates how to create a custom server using Express.js with the built SvelteKit application. The `handler` from the build directory is used to handle requests, and the server listens on a specified port.

```javascript
// server.js
import { handler } from './build/handler.js';
import express from 'express';

const app = express();

app.use(handler);

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
```

Environment Variables

This code demonstrates how to use environment variables with @sveltejs/adapter-node. The `env` option in the adapter configuration allows you to specify environment variables for the host and port. These variables can be defined in a `.env` file.

```javascript
// svelte.config.js
import adapter from '@sveltejs/adapter-node';

export default {
  kit: {
    adapter: adapter({
      env: {
        host: 'HOST',
        port: 'PORT'
      }
    })
  }
};

// .env
HOST=localhost
PORT=3000
```

Other packages similar to @sveltejs/adapter-node

FAQs

Package last updated on 14 Jan 2023

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