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

@zouloux/node-server

v1.1.3

Published

Node server with esbuild, watch mode, and a fastify proxy for dev assets.

Downloads

13

Readme

Node-server

Node-server will build your node based server with esbuild, and proxy your vite dev assets.

More info on deuspi

Install

npm i -D @zouloux/node-server

Features

Super fast

Will build your server with esbuild, so typescript included.

No module build.

Will keep all imported modules into node_modules directory without compiling them. This is easier to manage and avoid a lot of useless typescript errors.

Watch mode.

Will restart your server everytime you change the source-code of your server.

Plays well with vite

Includes a vite-proxy for dev mode ! ( continue reading bellow )

Server config

Config file can be named server.config.js to get along vite.config.js.

import { defineConfig } from "@zouloux/node-server";

defineConfig( mode => {
	// mode -> "dev" | "build" 
	return {
		input: 'src/server/server.ts',
		output: 'dist/server/server.js',
		dev: {
			command: 'node server.js --dev',
			cwd: 'dist/server'
		},
	}
})

More options

export interface INodeServerConfig
{
	// Bundle input and output
	input: string;
	output: string;
	// Dev mode
	dev?: {
		command: string
		cwd?: string
		killSignal?: string
	},
	// Es options
	esOptions?:Partial<BuildOptions>
	esPlugins?:Plugin[]
	// Logger
	logger?:ILogger
	logPrefix?:string
	// Env
	env?:any
}

Start server in dev mode

  • node-server dev

Build for production

  • node-server build

Custom config file

  • node-server build --config custom.server.config.js

With vite

Node-server plays well with vite. It will proxy vite assets from your Express / Fastify server in dev mode. In build mode, you can serve generated assets as static resources with Express / Fastify.

vite.config.js

import { defineConfig } from 'vite'
import { createCustomViteLogger } from "@zouloux/node-server";

export default defineConfig( viteConfig => {
	const isDev = viteConfig.mode === 'development'
	// We need a fixed port here because node server will proxy vite server
	const port = 5173
	return {
		// [ ... config ...]
		// Use custom vite logger for server-build
		...createCustomViteLogger({ isDev }),
	}
})

server.ts

import fastify from "fastify";
import { fastifyStatic } from "@fastify/static";
import { viteProxy } from "@zouloux/node-server/dist/vite-proxy.es2022.mjs";
// Create server
const server = fastify()
// Proxy vite in dev mode
if ( dev ) {
	viteProxy( server, {
		upstream: 'http://localhost:5173'
	})
// Serve vite generated assets in build mode
} else {
	server.register(fastifyStatic, {
		root: '../client',
		prefix: '/',
		list: false,
		dotfiles: 'deny'
	})
}
// Start server
server.listen({
	host: '0.0.0.0',
	port: 80
})

Package config

Here are some npm scripts to configure node-server and vite.

package.json

{
  "scripts": {
    "-- VITE --": "",
    "vite-dev": "vite dev --host",
    "vite-build": "vite build --emptyOutDir",
    "vite-clean": "rm -rf node_modules/.vite dist/client/* && echo Vite cache cleaned",
    "-- SERVER --": "",
    "server-dev": "node-server dev",
    "server-build": "node-server build",
    "server-start": "cd dist/server/ && node server.js",
    "-- BOTH --": "",
    "dev": "clear && (npm run vite-dev --silent & (sleep .6 && npm run server-dev --silent) & wait)",
    "build": "clear && npm run vite-build --silent && npm run server-build --silent",
    "preview": "npm run build --silent && npm run server-start --silent"
  }
}