npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-adapter-node-backend

v2.0.0

Published

Adapter for SvelteKit apps that allows injecting additional services into adapter-node's server instance

Downloads

5

Readme

svelte-adapter-node-backend

Install from NPM: npm install svelte-adapter-node-backend

Uses adapter-node to build a standalone Node server from a SvelteKit app, but allows injecting additional code into the server. This can be used to attach services to the server instance, such as a Socket.IO server.

In most cases, seperating the frontend and backend services is the better option in production. This module is meant more for prototyping, or cases where a monolithic application is preferred for ease of setup.

Tested using Node v20.11 on Linux.

Setup

Add the plugin to your vite.config.ts:

import backend from "svelte-adapter-node-backend/plugin";
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: [sveltekit(), backend()],
});

Use the adapter in your svelte.config.js:

import adapter from "svelte-adapter-node-backend/adapter";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: vitePreprocess(),

	kit: {
		adapter: adapter(),
	},
};

export default config;

Then, create the entry point file (src/lib/server/index.ts by default, see Options below). You must export two functions:

  • startBackend(server: Server) takes an instance of the Node built-in http.Server. You can pass the object to other modules so they can attach to the existing server.
  • stopBackend() must stop all services you have started in startBackend. This is used for HMR during development, to shutdown the previous version of the module before it is replaced and the new version is started. The method will not be called in production - so do not use it to, for example, persist data, as it will never be executed (see also: the adapter-node FAQ on the Svelte site).

Both of these functions can optionally be async. The functions will be awaited in development mode.

Options

You can pass an options object to both the plugin and adapter functions. Make sure both recieve the same options.

{
	// default options are shown
	entryPoint: "src/lib/server/index.ts", // file exporting the startBackend/stopBackend functions
}

The options object for the adapter function can also contain any of the options for adapter-node, which will be forwarded to that adapter.

Examples