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

dotweb

v0.5.132

Published

ready to use web server components

Downloads

9

Readme

.web

ready to use web server components based on MVC
 

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install dotweb

Fast development and ready to use

you should write a few lines to set up your server and continue with writing your model and controllers. dotweb detect your paths and connect all source codes together.
 

  • not necessary to build any router
  • not necessary to require files
  • not necessary to know about web servers
  • not necessary to understand what I say
     

Just make these 3 files to start:


MyApp/app.js

const { Application } = require("dotweb");

// provide an application initializer
const application = new Application("MyApp");

// initialize necessary services
application.start.redis();
application.start.mongoose("mongodb://localhost:27017/MyApp");
application.start.express();
application.start.http(8000);

// initialize all models dynamically
application.external("models");

// initialize all controllers dynamically
application.external("controllers");


MyApp/models/record.js

const { ModelMongoose } = require("dotweb");
const { Schema } = require("mongoose");

module.exports = class extends ModelMongoose {
  // build a new mongoose schema
  schema() {
    return new Schema({
      name: { type: String, required: true },
      number: String,
      address: String,
    });
  }
};


MyApp/controllers/api/record.js

const { Controller } = require("dotweb");

module.exports = class extends Controller {
  // handle all post requests
  post(params) {
    const { record } = this.application.models;
    return record(params).save();
  }
  // handle all get requests
  get() {
    const { record } = this.application.models;
    return record.find();
  }
};

do not need to restart your node service on file changes.


 

Full Package is Available Now

start any service jut by one application.start command:


 

start redis cache service:

application.start.redis();


 

start mongoose database service:

application.start.mongoose(mongoURL);

mongoURL: mongodb connection link.


 

start jsonwebtoken authorization service:

application.start.jsonwebtoken(secret);

secret: jsonwebtoken passphrase or secret.


 

start express web service:

application.start.express(build, messages);

build: server build will return in any api calls.

messages: server error messages.

default massages are:

const messages = {
  0: "successfully respond",
  10: "no response from server",
  11: "unknown error",
  12: "wrong api address",
  13: "method not found",
  14: "access denied",
  15: "no response delivered in request deadline",
  16: "internal server error",
  17: "authorization failed",
  18: "fail to handle too many requests",
  19: "license expired",
  20: "controller not found",
  21: "no response",
  22: "no response from controller",
  23: "wrong api version",
};


 

start http listener service:

application.start.http(port);

port: listening port.


 

start https listener service:

application.start.https(options, port);

options: https need some options to start.

const fs = require("fs");

const options = {
  key: fs.readFileSync("privkey.pem"),
  cert: fs.readFileSync("cert.pem"),
  passphrase: "haShSEcrEt",
};

port: listening port.


 

start firebase messaging service:

application.start.firebase(credential, databaseURL);

credential: firebase account credential.

databaseURL: firebase account database url.


 

start socket.io service:

application.start.socket(build, messages);

build: server build will return in any api calls.

messages: server error messages.

default massages are:

const messages = {
  0: "successfully respond",
  10: "no response from server",
  11: "unknown error",
  12: "wrong api address",
  13: "method not found",
  14: "access denied",
  15: "no response delivered in request deadline",
  16: "internal server error",
  17: "authorization failed",
  18: "fail to handle too many requests",
  19: "license expired",
  20: "controller not found",
  21: "no response",
  22: "no response from controller",
  23: "wrong api version",
};


 

Extra Features


use cache in controllers

const { Controller, cacheState } = require("dotweb");

module.exports = class extends Controller {
  override() {
    return {
      cacheState: cacheState.public,
      cacheExpire: 100,
    };
  }
  post(params, { id, ip, domain, method, role, userId, deviceId, login }) {
    return `
      <h2>This content will cache for 100 seconds</h2>
      <p>for exactly the same requests.</p>
    `;
  }
};


extra request info in controllers

const { Controller } = require("dotweb");

module.exports = class extends Controller {
  post(params, { id, ip, domain, method, role, userId, deviceId, login }) {
    return `
      <p>request id: ${id}</p>
      <p>client ip: ${ip}</p>
      <p>access domain: ${domain}</p>
      <p>request method: ${method}</p>
      <p>authorized user role: ${role}</p>
      <p>authorized user id: ${userId}</p>
      <p>authorized user device id: ${deviceId}</p>
      <p>authorized user login time stamp: ${login}</p>
    `;
  }
};


make custom error messages in controllers

const { Controller } = require("dotweb");

module.exports = class extends Controller {
  override() {
    return {
      messages: {
        101: "this is a test message",
      },
    };
  }
  post() {
    throw 101;
  }
};


use validator in models

const { ModelMongoose } = require("dotweb");
const Mongoose = require("mongoose");
const Joi = require("joi");
const Joigoose = require("joigoose")(Mongoose);

module.exports = class extends ModelMongoose {
  schema() {
    const joiSchema = Joi.object({
      name: Joi.string().required(),
      username: Joi.string().min(6).max(30).required(),
      password: Joi.string()
        .min(8)
        .max(30)
        .regex(/[a-zA-Z0-9]{3,30}/)
        .required(),
      mobile: Joi.string().required(),
      email: Joi.string().email().required(),
      created: Joi.date(),
    });
    const schema = Mongoose.Schema(Joigoose.convert(joiSchema));
    schema.path("created").default = new Date();
    schema.index({ username: 1 }, { unique: true });
    return schema;
  }
};


 
It's a beginning; more tools will available soon..