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

rootz-express-ts-boilerplate

v1.0.3

Published

A boilerplate for creating express server with typescript

Downloads

5

Readme

rootz express-ts boilerplate

This is a boilerplate for express-ts project.

Features

  • [x] Automatic routes registration, no need to manually add routes to the app. Just create a file in the routes folder and follow the RouteOption interface to define your route.

  • [x] Automatic middleware registration. Just like routes, create a file in the middleware folder and follow the MiddlewareOption interface to define your middleware.

  • [x] Configurable environment variables. Use config.ts to add different client configurations with typing support, all in one place.

Getting Started

Dependencies

Steps

  1. Fetch the project as boilerplate
npx rootz-express-ts-boilerplate <project-name>
  1. Install dependencies
cd my-app
npm install
  1. Start the server
npm run dev:server
  1. Start the worker (in a separate terminal, optional)
npm run dev:worker
  1. Open the browser and navigate to http://localhost:<PORT>/api/hello

  2. You should see a response from the server & terminal logs from the worker and middleware as PoC that they are being executed.

Server - Worker Architecture

This boilerplate uses a server-worker architecture. The server is responsible for handling incoming requests and the worker is responsible for processing the requests. This architecture allows the server to be free from processing heavy tasks and focus on handling incoming requests.

Server

The server is connected to the worker through a message queue (Redis channel). The server listens to incoming requests and sends the request to the worker for processing. The server doesn't wait for the worker to finish processing the request, it immediately sends a response to the client.

Worker

  • The worker subscribes to the message queue and listens for incoming messages. When a message is received, the worker processes the payload.

  • The worker doesn't have access to the request object, so it can't send a response to the client. Make sure these tasks are asynchronous and don't require a response for end user.

Components

Middleware

  • Middleware is a function that runs before the route handler. It can be used to perform tasks like logging, authentication, etc.

  • Default project comes with a sample middleware that logs the request method, url, and response time.

  • path: You can also define path specific middleware by adding a path in the middleware options.

  • prioirty: Middleware can be executed in a specific order by setting the priority. Lower the number, higher the priority.

  • func: Middleware function that runs before the route handler, it takes 4 arguments: req, res, next, content.

  • context: Middleware is also able to access the context object which contains the instance of services like redis, mongo, etc.

Routes

  • Routes are automatically registered by the server. Just create a file in the routes folder and follow the RouteOption interface to define your route.

  • To generate a route, you can use the generate-route command.

npx rootz-express-ts-boilerplate generate-route <route-name>