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

hastejs-cli

v0.1.0

Published

A nodejs Framework for develop API in record time.

Downloads

6,949

Readme

HasteJS - A nodejs framework.

NPM License: MIT HasteJs CI

HasteJS is a NodeJs framework, built on top of ExpressJS, released as free and open-source software under the MIT Licence. It is particularly designed to develop a quick Restful API in record time.

Details Docs: http://hastejs.com

Netlify Status

Node.js
HasteJs only requires Node.js. The current recommended version to run Haste is Node v14.

Installation and run in development mode
npx create-haste-app my-app
cd my-app
npm run develop

Module

What is Module in HasteJs?

In HasteJs, Modules are some smaller part of your entire project. You may want to divide your entire project into some modules so that you can easily use these modules for your other hasteJs project easily.

Create a new module

It is very easy to create a new module in your hasteJs project. Just run below comand on your project root.

npx create-module moduleName

It will generate a new folder in app directory with controllers, model and routes.

.
└── app
    └── moduleName
        ├── controller.js
        └── model.js
        └── routes.json

Remove an existing module

If you want to remove a module, just run below command on your project root -

npx remove-module moduleName

Note: Don't delete a folder or module manually from app directory. That may cause unnecessary error on your code.

Routes

Routes refer to how Rest API's endpoints respond to client requests. When you create a new module, haste by default create some REST convention endpoint for you. Here, You can add new endpoints or update old endpoints as your need.

{
  "routes": [
    {
      "method": "GET",
      "path": "/category",
      "controller": "category.find",
      "config": {
        "middleware": []
      }
    },
    {
      "method": "GET",
      "path": "/category/count",
      "controller": "category.count",
      "config": {
        "middleware": []
      }
    },
    {
      "method": "GET",
      "path": "/category/:id",
      "controller": "category.findOne",
      "config": {
        "middleware": []
      }
    },
    {
      "method": "POST",
      "path": "/category",
      "controller": "category.create",
      "config": {
        "middleware": []
      }
    },
    {
      "method": "PUT",
      "path": "/category/:id",
      "controller": "category.update",
      "config": {
        "middleware": []
      }
    },
    {
      "method": "DELETE",
      "path": "/category/:id",
      "controller": "category.delete",
      "config": {
        "middleware": []
      }
    }
  ]
}

Controller

Every route passes the request to the defined controller. Controllers hold the business logic of your module. Every route must define a controller. Controllers can communicate with the model and return data to the client or Error handlers.

import {Model as Category} from '../../database/modelMapper.js'

const controller = {
    async count(req, res, next){
        try {
            const response = await Category.count({});
            res.json({total: response});
        } catch (err) {
            next(err);
        }
    },
}
export default controller;

The above code is responsible for the return count of the Category.

If you need to add a new function to your controller, you must add it to your routes.json file with the proper structure.

Model

HasteJs uses sequelize for managing database operations. For updating your model you need to update your model.js file to structure your table. For more about sequelize model visit here: https://sequelize.org/master/manual/model-basics.html

Example model:

import {sequelize} from "../../database/index.js";
import DataTypes from 'sequelize';

export const Model = sequelize.define('Category', {
    // Model attributes are defined here
    // This are example attributes. please change as you want.
    // visit https://sequelize.org/master/manual/model-basics.html for details.

    title: {
        type: DataTypes.STRING,
        allowNull: false
    },
    description: {
        type: DataTypes.STRING
        // allowNull defaults to true
    }
}, {
    // Other model options go here
});

Relation/Association

You can define all your relation/association here database/relation.js file.

Example

import {Post, Category} from "./modelMapper.js";

const relation = ()=> {
    Post.belongsTo(Category, {foreignKey: 'category_id'})
    Category.hasMany(Post, {
        foreignKey: 'category_id',
        sourceKey: 'id'
    })
}

export default relation();

Default Module

When you create a HasteJs project by create-haste-app, A default User module will automatically generate for you in your app directory, So that you can focus on your main modules to develop your app in haste mode. This default user module provides the following API

- Login user
- Register user
- Count all users
- Find Me
- Find all users
- Find Specific user.



License & copyright
© MD SULTAN MAHAMUD, Software Engineer
Licensed under the MIT License.