Skip to content

Simple MVC boilerplate for building web application using Express, Knex, MariaDB, Nunjucks and Bulma.

Notifications You must be signed in to change notification settings

budasuyasa/mvc-express-boilerplate

Repository files navigation

Express MVC Boilerplate

Simple MVC boilerplate for building web application using Express, Knex, MariaDB, Nunjucks and Bulma.

Whats's Includes

Install

  • Clone this repository and cd to target directory
  • Install required depedencies using npm install
  • Create new .env file for environtment variables. Copy from .env.example cp .env.example .env
  • Edit and set site host, port and database configuration on .env file

Run Dev Server

Run npm run dev to start development server. Go to http://localhost:5000. Every file changes will automaticaly refresh your browser.

IDE Configs

If you use Visual Studio Code, consider to install extentions bellow to make your life easier and happier:

  • vscode-nunjuks : Nunjucks template syntax definition specifically for Microsoft Visual Studio Code.
  • Auto Close Tag : For autoclose html tag. Please add njk in auto-close-tag.activationOnLanguage config property if not included yet

Models

For this moment this application is not using any database models/schema. All database interaction handled using Knex query builder. You can access Knex instance via req.db object anywhere on application scope.

Example:

req.db.select('id','name').from('users');

Routes

Every routes stored in /routes directory. Routes uses as middleware in express application.

Controllers

Every controllers stored in /controllers directory. Plain and simple Javascript module.

Views

Every view file (with .njk extension) stored in /views directory. You can access global variables for view data via req.viewData object. Some ommon view variables such as:

  • baseUrl : site base url
  • data : CRUD data
  • queryParams : CRUD query parameters such as:
    • page : pagination
    • search : keyword for search
    • limmit and offset
  • and many more

License

MIT

About

Simple MVC boilerplate for building web application using Express, Knex, MariaDB, Nunjucks and Bulma.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published