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

@luly/cli

v2.0.0

Published

CLI for a Basic Backend Development Framework with Hexagonal Architecture based on Express

Downloads

13

Readme

Luly: Basic Backend Development Framework with Hexagonal Architecture based on Express

Global Installation

npm install -g @luly/cli

Create a new project

luly new project_name

Add a new module

luly create module module_name

This command creates a module structure:

module-name
    |----Application
    |     |----module-name.service.ts
    |     |----Controller
    |           |----module-name.controller.ts
    |----Domain
    |     |----Interfaces
    |            |----module-name.interface.ts
    |----Infrastructure
        |----module-name.repository.ts

Controllers

Controllers for each module are created when generating the module. To use these controllers, you need to register them in the router.ts of the project, located at project-name/src/router.ts.

//router.ts
const controllers = [UserController];
const appRouter = setRoutes(controllers, express.Router());

These controllers use decorators to define routes and middlewares.

Router

Use @Router('path') to specify a general route for the controller. Use it before the class. Example:

@Router("user")
export class UserController {
}

Methods

You can use the following decorators to define method routes:

  • @Post('path')
  • @Get('path')
  • @Put('path')
  • @Delete('path')

The path in decorators follows Express logic, so you can pass parameters in the same way, like @Get('user/:id').

When using decorators, methods inherit req, res, and next from Express.

Example:

@Post('user')
createUser(req, res, next) {
    const { name, last_name } = req.body;
    res.send({
        message: "User created successfully"
    });
}

Middleware

The @Middleware([]) decorator takes an array of middlewares as a parameter. These middlewares run before each method in the order they are listed. This decorator should be placed after the method's decorator and before the method itself. Also it works after @Router('')

Example:

@Get('user')
@Middleware([authMiddleware, secondMiddleware])
getUser(req, res, next) {
}

Middleware example:

//authMiddleware.ts
function authMiddleware(req, res, next) {
    //your code here
    next();
}
export default authMiddleware;

Build

To compile the project, use the following command:

luly build

Compiled files are generated by default in /dist. You can configure tsconfig.json to change the output dir.

You can do a node dist/index.js to execute the compiled proyect.

CLI

The luly.config.json file is only necessary to specify the main project path to Luly. The contents of luly.config.json are not used in the framework; this file is only used for verification of being in the main path of a Luly project. In the future, it may be used to add necessary information.