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

londor

v1.0.1

Published

A tiny typescript and express based web framework

Downloads

5

Readme

Londor - Tiny and Neat Express

Londor is a nice little service based framework on top of express. It's 2 core values

  • Decrease Abstractions
  • Increase Readability
  • It doesn't hide anything from express

Getting Started

  1. You'll need Node 6.10.x or higher
  2. We highly recommmend using TypeScript 2.5.1 or higher
  3. Your tsconfig.json file will need:
    • to target es6
    • use commonjs
    • set experimentalDecorators to true
    • set emitDecoratorMetadata to true
  4. Run npm install londor --save

It should look something like below.

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
  },
  "exclude": [
    "node_modules"
  ]
}

Examples

A simple server

import { Server } from 'londor'

const server = new Server({
  port: 4000
})

server.start()
  .then(() => {
    console.log("The server is started on port 4000!")
  })
  .catch((err) => {
    console.error(err)
  })

Adding a service

A service is just a class that you can add to a Server instance.

  • You can expose methods as http endpoints using @Get, @Post, @Put, @Delete etc...
  • You can read parameters using the @Param('carId') or just @Param decorator
  • Services don't need http endpoints at all
import { Server, Get, Post, Put, Delete, BaseRoute, Body } from 'londor'

@BaseRoute('/cars')
class CarService {

  cars = [{
      carId: 1,
      name: 'toyota',
    }, {
      carId: 2,
      name: 'ford',
    }]

  @Get('/all')
  getAllCars(){
    return this.cars
  }

  @Post('/')
  async addNewCar(@Body body: any) {
    this.cars.push(body.car)
    return body
  }

  @Put('/:carId')
  async updateCar(@Body body: any) {
    this.cars.push(body.car)
    return body
  }

  @Delete('/:carId')
  async deleteCar(@Param carId: string) {
    for(let car of this.cars) {
      if (car.carId === carId) {
        this.cars.splice(this.cars.indexOf(car), 1)
      }
    }
  }

}
const server = new Server({
  port: 4000
})

server.addService(new CarService())

server.start()
  .then(() => {
    console.log("The server is started on port 4000!")
  })
  .catch((err) => {
    console.error(err)
  })

Using Express Middlewares

The server can easily attach express middlewares. Simply use the familiar use functionality

import * as cors from 'cors'
server.use(cors())

Express Middlewares in Services

You can add additional middlewares before

import { Get, UseMiddleware } from 'londor'

Serving Static Files

Serving Static Files is super easy with @ServeStatic

  • The first parameter is the route of the static file
  • The second parameter is the path to file to serve.

This is simply a wrapper around express.static API

import { ServeStatic, BaseRoute } from 'londor'
@BaseRoute('/dashboard')
@ServeStatic('/', 'path/to/index.html') 
@ServeStatic('/admin', 'path/to/admin.html') 
class DashboardService {
  // .. more implementation goes here
}
server.addService(new DashboardService())
server.start()
  .then(() => {
    console.log("The server is started on port 4000!")
    console.log("The dashboard is at http://localhost:4000/dashboard")
    console.log("The admin panel is at http://localhost:4000/dashboard/admin")
  })
  .catch((err) => {
    console.error(err)
  })

Contributing

After npm install

  1. To Build npm run build
  2. To Clean Artifacts npm run clean
  3. To Test npm run test
  4. To Lint npm run lint
  5. To Buld and Watch when you make changes npm run watch

Debugging with Visual Studio Code

  1. Set a breakpoint in your code ending in .ts or your test ending in .spec.ts
  2. Run Either Launch Program or Launch Tests in the debug pane.
  3. Run Either Launch Program or Launch Tests in the debug pane.