
Adapter for SvelteKit apps that generates a standalone Node server with support for WebSockets.
The @carlosv2/adapter-node-ws is an adapter for SvelteKit apps that allows for the generation of a standalone Node server with support for WebSockets. This package utilizes the ws library to provide the WebSocket functionality. While there may be some shortcuts taken due to SvelteKit not being fully ready yet, the adapter aims to provide a convenient package for building WebSockets on top. The author acknowledges that this package may not suit everyone's needs but welcomes PRs for potential improvements.
To use the @carlosv2/adapter-node-ws in a SvelteKit app during development, follow these steps:
// Change original HMR port from Vite
// This does not affect functionality but introduces minimal configuration
export default defineConfig({
server: {
hmr: {
port: <desired port number>
}
},
});
import wsPlugin from '@carlosv2/adapter-node-ws/plugin';
export default defineConfig({
plugins: [wsPlugin()],
});
To use the @carlosv2/adapter-node-ws in a SvelteKit app during production, simply replace your existing adapter in the svelte.config.js file with this one:
import adapter from '@carlosv2/adapter-node-ws';
export default {
kit: {
adapter: adapter(),
},
};
Please note that since this adapter is based on @sveltejs/adapter-node, any configuration meant for that adapter is still valid and applicable to this one.
The @carlosv2/adapter-node-ws is a helpful adapter for SvelteKit apps that allows for the generation of a standalone Node server with WebSockets support. It provides features such as individual environment configuration, compatibility with @sveltejs/adapter-node, and support for both development and production environments. While there may be some limitations and room for improvement, the adapter aims to provide a convenient solution for building WebSockets on top of SvelteKit. It is licensed under the MIT license.

RollupJS is a popular and efficient JavaScript module bundler that takes the code from multiple modules and packages them into a single optimized file, minimizing the overall size of the application and improving its performance.
TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.