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 🙏

© 2025 – Pkg Stats / Ryan Hefner

simplemvcjs

v0.9.7

Published

A highly opinionated MVC micro web-framework.

Readme

SimpleMVC.js

A highly opinionated MVC micro web-framework for Node.js

Examples

  1. Simple Blog

    Shows the basic use of routing, views, static files, and the SimpleMVC.SMTP class.

  2. Simple SaaS - Coming Soon

    Utilizes all parts of the SimpleMVC library (routing, views, json responses, static files, SMTP, and Membership)

  3. Shortlinker

Quick Start

This quick start assumes atleast a base familiarity with Node.js, NPM, and how to build a website.

  1. Initialize your NPM package

    npm init, and fill out the questions

  2. Include simplemvc.js in your project

    1. By downloading and including simplemvc.js manually in your project.
    2. Through npm by running npm install simplemvcjs
  3. Create and/or open app.js

  4. Import/Require SimpleMVC

    const SimpleMVC = require('simplemvcjs');

    or if you downloaded the project

    const SimpleMVC = require('/path/to/simplemvc.js');

  5. Create your first SimpleMVC.Controller

    const HomeController = new SimpleMVC.Controller("/", {
        "": function() {
            return this.content("Hello, World!");
        }
    });
  6. Create your your SimpleMVC.App

    const app = new SimpleMVC.App();
    app.addControlers(HomeController);
    app.listen();
  7. Create your dotenv file

    #server
    HOST=localhost
    PORT=8080
    SESSION_SECRET=
    
    #database
    MONGO_SCHEME=
    MONGO_USER=
    MONGO_PASSWORD=
    MONGO_SERVER=
    MONGO_DB=
    
    #smtp
    SMTP_USER=
    SMTP_PASS=
    SMTP_HOST=
    SMTP_PORT=
    SMTP_SECURE=
  8. Run it via node ./app.js

Project Structure

While SimpleMVC is highly opinionated, we have a relatively lax project structure requirement. There is a specific structure for the core files required.

/.env       - this is the dotenv file the sets your application's global variables
/app.js     - this can be any name, but throughout documentation it will be refered to as your app.js
/views/     - the root directory for your view templates
/static/    - the root directory for your static files

These directories would be relative to your app.js file and are required for finding specific views and static content.

Routing

Routing in SimpleMVC is defined by the combination of a base path (the first constructor parameter) and a routes dictionary (the second constructor parameter), and can then be expanded after initialization through the Controller.addRoutes() function.

const HomeController = new SimpleMVC.Controller("/", {
    "": function() {
       return this.view('index');
    }
})

Individual routes are defined as such:

HomeController.addRoutes({
   "route/path": function(req, res) {
        const model = { someProperty: "some value" };
        return this.view('viewName', model);
    }
});

In the previous example, if the controller's base path was defined as "/", the route would be /route/path and the view file would be located at ./src/views/viewName.

Views

Views are Mustache(5) templates. And when you return a view with a model from your route, the model will be accessed as {{model}} inside the Mustache templates.

All views need a .html file extension.

A Simple Example

const SimpleMVC = require('../libs/simplemvc.js');
const BlogService = require('./services/BlogService.js');

const HomeController = new SimpleMVC.Controller("/", {
    "": async function () {
        const latestPosts = await BlogService.getPostsDesc(0, 10);
        let view = {
            title: "My Website",
            posts: latestPosts,
        };
        return this.view('index', view);
    },
    "post/:id": async function (req) {
        const post = await BlogService.getPost(req.params.id);
        return this.view('single', post);
    },
    "about": function () {
        return this.view('about', { title: "About Me" });
    }
});

const app = new SimpleMVC.App();
app.initDbConnection();
app.addControllers(HomeController);
app.listen();