Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
widget-cms
Advanced tools
A highly modular Node.js application framework
Widget-CMS
is a framework for building Node.js applications that use SQL databases. Under the hood it uses Bookshelf.js to connect to the database and supports the following databases: Postgres, MySQL, MariaDB, and SQLite. Widget-CMS
follows a MVC-like architecture and is built around the following concepts - Models
, Collections
, Controllers
, Routes
, Plugins
, and Widgets
.
When a Widget-CMS
application is initialised it runs the following steps:
multer
instance that will be used for handling multipart formswidget-cms
inside your root directory: npm install widget-cms --save
mkdir models collections controllers widgets plugins routes
"use strict";
const app = require('widget-cms');
const path = require('path');
app.config({
port: 3000, // default 3000
secret: 'your_app_secret_here',
saveLogs: true, // write application logs to files
db: { // required
client: 'mysql', // options - mysql, pg, mariasql, sqlite3
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'widget_cms',
charset: 'utf8'
}
},
redis: {}, // optional - assumes {host: localhost, port: 6379}
cache: true, // optional - defaults to false
rootDir: process.cwd(), // required
/**** optional
viewsDir: path.join(process.cwd(), 'views'), // optional - defaults to ./views
modelsDir: path.join(process.cwd(), 'views'), // optional - defaults to ./models
collectionsDir: path.join(process.cwd(), 'views'), // optional - defaults to ./collections
controllersDir: path.join(process.cwd(), 'views'), // optional - defaults to ./controllers
widgetsDir: path.join(process.cwd(), 'views'), // optional - defaults to ./widgets
pluginsDir: path.join(process.cwd(), 'views'), // optional - defaults ./plugins
*****/
middleware: {
enableForms: true,
enableCSRF: true,
enableSessions: true
}
});
app.registerMiddleware(function (req, res, next) {
// pass user object to templates
res.locals.user = {
name: 'Que',
email: 'que@widget-cms.com'
};
next();
});
app.start();
All models should be located in the models directory. Models are created by extending the widget-cms Model object.
const App = require('widget-cms');
const User = App.Model.extend({
tableName: 'users'
});
module.exports = App.addModel('User', User);
Widget-CMS Models have 5 special methods that you can use to handle certain events when your model is initialized:
const App = require('widget-cms');
const User = App.Model.extend({
tableName: 'users',
// called before an insert or update query
// throw error to cancel operation
// should return a promise for async operations
saving: function (model, attributes, options) {
// do validations and data transformations
},
// called before an insert query
// throw error to cancel operation
// should return a promise for async operations
creating: function (model, attributes, options) {
// do validations and data transformations
},
// called before a delete query
// throw error to cancel operation
// should return a promise for async operations
destroying: function (model, attributes, options) {
// do validations
},
// called after an insert or update query.
saved: function (model, attributes, options) {
},
// called after an update query
updated: function (model, attributes, options) {
}
});
module.exports = App.addModel('User', User);
All collections should be located in the collections directory. Collections are created by extending the widget-cms Collection object.
const App = require('widget-cms');
const User = App.getModel('User');
const Users = App.Collection.extend({
model: User
});
module.exports = App.addCollection('Users', Users);
All controllers should be located in the controllers directory. Controllers are created by extending the widget-cms Controller object.
const App = require('widget-cms');
const UsersController = App.Controller.extend({
getUsers: function (req, res, next) {
let Users = App.getCollection('Users');
Users.forge()
.then(function (collection) {
res.json(collection.toJSON());
})
.catch(function (error) {
next(error);
});
}
});
module.exports = App.addController('Users', getUsers);
All routes should be located in the routes directory. Routes can be created by calling the get
or post
methods directly from the widget-cms object.
const App = require('widget-cms');
const UsersController = App.getController('Users');
App.get('/users', UsersController.getUsers);
The Widget-CMS API is intentionally kept small, please send open an issue for any bugs.
config - sets application configuration
registerMiddleware - registers express server middleware. registered at the bottom of the middleware stack
registerHelper - registers handlebars helpers
start - initializes the application and starts the server
addCollection - add a collection to application
addModel - adds a model to application
addController - adds a controller to application
hasController - checks is a controller method exists
getPlugin - get a registered plugin
getController - gets a created controller
getControllers - gets a all stored controllers and their methods
getModel - gets an application model
getCollection - gets an application collection
getConfig - gets application configuration
get - creates application get routes. It's syntactic sugar on top of express' get method
post - creates application post routes. It's syntactic sugar on top express' post method
clearCache - clears application cache
passport - passport authentication
Below is a list of application objects that are extendable.
Checkout changelog.md starting from v0.3.6
npm test
(MIT License)
Copyright (C) 2016 Qawelesizwe Mlilo qawemlilo@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
A highly modular Node.js application framework
The npm package widget-cms receives a total of 1 weekly downloads. As such, widget-cms popularity was classified as not popular.
We found that widget-cms demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.