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

@javierbonet/express-templating

v0.1.4

Published

<h1 align="center"> express-templating </h1> <p align="center"> <b>Simplify your API implementation process by generating the default files structure</b> </p>

Downloads

2

Readme

Description

Utility that contains commands to accelerate building express APIs by generating the different directories and files for a standard set of files when creating an endpoint:

  • Files:
    • /routes
      • /routes/resourceNameRoutes.ts
    • /services
      • /services/resourceNameService.ts
    • /repositories
      • /repositories/resourceNameRepository.ts

In the files above resourceName will be replaced with the resource name passed as argument when executing the command in the command line. The commands included in this utility are thought considering a project that uses:

Installation

NPM

npm i -D @javierbonet/express-templating

Yarn

yarn add --dev @javierbonet/express-templating

Commands

Resource generation

npx @javierbonet/express-templating generate-resource user field1:number field2:string

This command will generate the following structure:

├── database
│   ├── entities
│   │   └── User.ts
│   └── data-source.ts
├── src
      ├── routes
      │   └── userRoutes.ts
      ├── services
      │   └── userService.ts
      ├── repositories
          └── userRepository.ts

Parameters

  • name: to be used when defining the files for the resource.
  • properties list to be used as field for the entity to create: format propertyName:type

Options

  • dbEngine: database engine to be used in the data source configuration file
    • default: mysql
  • dbPort: database port to be used in the data source configuration file
    • default: 3306
  • dbDirectory: name of the directory where the data source and entities will be placed
    • default: database
  • srcDirectory: name of the directory where the routes, service and repository files will be placed
    • default: src

userRoutes.ts

Sets express routes to enable the following actions:

  • GET /: to retrieve all resource instances
  • GET /:id: to retrieve an specific resource instances
  • POST /: to create a new resource instances
  • PUT /:id: to update an specific resource instances
  • DELETE /:id: delete an specific resource instances

userService.ts

The service use the repository to access the database. Contains the following methods.

  • getAll(): retrieves all the users stored in the database
  • getById(id: number): retrieves the specific user from the database
  • create(user: userProperties): creates a user in the database
  • update(id: number, userProperties): updates a user in the database
  • delete(id: number): deletes a user from the database

userRepository.ts

Contains the following methods:

  • getAll(): retrieves all the users stored in the database
  • getById(id: number): retrieves the specific user from the database
  • create(user: userProperties): creates a user in the database
  • update(id: number, userProperties): updates a user in the database
  • remove(id: number): deletes a user from the database

Special mentions

Thanks to Simone Scigliuzzi. I borrowed his pretty printing class explained here.