Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@sveltejs/adapter-node
Advanced tools
[Adapter](https://kit.svelte.dev/docs#adapters) for SvelteKit apps that generates a standalone Node server.
@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.
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
```
@sveltejs/adapter-static is an adapter for SvelteKit that allows you to build your application as a set of static files. This is useful for deploying to static hosting providers like GitHub Pages or Netlify. Unlike @sveltejs/adapter-node, it does not require a Node.js server.
@sveltejs/adapter-vercel is an adapter for SvelteKit that allows you to deploy your application to Vercel. It is specifically designed to work with Vercel's serverless functions and deployment platform. This adapter abstracts away the server setup, unlike @sveltejs/adapter-node, which requires a custom server.
@sveltejs/adapter-netlify is an adapter for SvelteKit that allows you to deploy your application to Netlify. It is designed to work with Netlify's serverless functions and deployment platform. Similar to @sveltejs/adapter-vercel, it abstracts away the server setup.
Adapter for SvelteKit apps that generates a standalone Node server.
Install with npm i -D @sveltejs/adapter-node@next
, then add the adapter to your svelte.config.js
:
// svelte.config.js
import adapter from '@sveltejs/adapter-node';
export default {
kit: {
adapter: adapter({
// default options are shown
out: 'build',
precompress: false
})
}
};
The directory to build the server to. It defaults to build
— i.e. node build
would start the server locally after it has been created.
Enables precompressing using gzip and brotli for assets and prerendered pages. It defaults to false
.
By default, the server will accept connections on 0.0.0.0
using port 3000. These can be customised with the PORT
and HOST
environment variables:
HOST=127.0.0.1 PORT=4000 node build
FAQs
Adapter for SvelteKit apps that generates a standalone Node server
The npm package @sveltejs/adapter-node receives a total of 80,350 weekly downloads. As such, @sveltejs/adapter-node popularity was classified as popular.
We found that @sveltejs/adapter-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.