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

node-badger

v1.2.8

Published

node-badger a framework for building node applications.

Downloads

5

Readme

node-badger

node-badger is a node framework which creates a node-server project upon the MVC design pattern. The framework would setup your node application for both dev and production. Once project setup is complete you can run your server.

Build Status

Installation

npm install -g node-badger

Usage

On your terminal run the command to create a node-server project

node-badger

It will create a directory structure, including the files you need to kick off your next node-server project. Inside that directory, it will create the initial project structure and install the transitive dependencies:

yourprojectname
├── README.md
├── node_modules
├── package.json
├── local.js
└── test
└── src
    └── config
        └──params.js
    └── controllers
    └── models
    └── views
        └── index.html
    └── routers
    └── server.js

Once the project setup is complete, you can run your server:

npm run start

And you should see this log on your screen:

Listening on: port 8000
mongoDB connected

Or

npm run server

And you should see this log on your terminal:

[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node local.js`
Listening on: port 8000
mongoDB connected

Go to your browser and access http://localhost:8000/. You should see; It works!

Selecting database type

During your project setup, you can specify which database you'd be using for your project.

Creating models, routers and controllers for your project

Models, Routers and Controllers can be generated for your project. For now, node-badger supports model generations with mongoose. To create models for your project, you run the command node-badger-mongoose-model with (-m) to specify model name, and (-a) for model attributes:

node-badger-mongoose-model -m UserModel -a "firstname:String,lastname:String,emailaddress:String"

The above command will generate a mongoose model that looks like this:

const mongoose = require("mongoose");
const userModelSchema = mongoose.Schema({
firstname : {
            type : String,
            required: "firstname is required",
            },
lastname : {
            type : String,
            required: "lastname is required",
            },
emailaddress : {
            type : String,
            required: "emailaddress is required",
            },
}, {collection:"usermodel", timestamps : true});
    const userModel = ConnectMongo.model("userModel", userModelSchema);
    module.exports = {userModel};

A controller that looks like this:

const UserModel = require('../../src/models/UserModel');
        
// Display a list of all User.
exports.User_list = function(req, res) {
    res.send('NOT IMPLEMENTED: User list');
};
        
// Display a specific User.
exports.User_detail = function(req, res) {
    res.send('NOT IMPLEMENTED: User detail: ' + req.params.id);
};
        
// Display User create form on GET.
    exports.User_create_get = function(req, res) {
    res.send('NOT IMPLEMENTED: User create GET');
};
        
// Handle User create on POST.
exports.User_create_post = function(req, res) {
    res.send('NOT IMPLEMENTED: User create POST');
};
        
// Display User delete form on GET.
exports.User_delete_get = function(req, res) {
    res.send('NOT IMPLEMENTED: User delete GET');
};
        
// Handle User delete on POST.
exports.User_delete_post = function(req, res) {
    res.send('NOT IMPLEMENTED: User delete POST');
};
        
// Display User update form on GET.
exports.User_update_get = function(req, res) {
    res.send('NOT IMPLEMENTED: User update GET');
};
        
// Handle User update on POST.
exports.User_update_post = function(req, res) {
   res.send('NOT IMPLEMENTED: User update POST');
};
        

And a router that looks like this

var routerModule = require("../../src/server")
const router = routerModule.router;
// Require controller modules.
const User_controller = require('../../src/controllers/UserController');

/// User ROUTES ///

// GET request for one User.
router.get('/:id', User_controller.User_detail);

// GET request for list of all User items.
router.get('/getall', User_controller.User_list);

// GET request for creating a User. NOTE User (uses id).
router.get('/create', User_controller.User_create_get);

// POST request for creating a User.
router.post('/create', User_controller.User_create_post);

// GET request to delete User.
router.get('/:id/delete', User_controller.User_delete_get);

// POST request to delete User.
router.post('/:id/delete', User_controller.User_delete_post);

// GET request to update User.
router.get('/:id/update', User_controller.User_update_get);

// POST request to update User.
router.post('/:id/update', User_controller.User_update_post);
        
module.exports = router;

when specifying a model name, it is necessary to include "Model" in your model name, looking like this "UserModel". And make sure your data types are in the correctly written : String, [], {}, Number.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT