Build a blog with Areto Node.js framework

The first controller

The Areto Node.js framework uses the MVC pattern (Model - View - Controller) popular among web applications for interaction between the different parts of the app.

Default Controller

Create the controllers directory in the root of the project and append the DefaultController.js file. The filename is the name for exported class. The controller class inherits from the area/base/Controller framework class.

Note that is exported class definition itself,     instead created instance, as was the case with module.js.

Create the actionIndex class method. All controller methods with the action prefix are defined as actions (handlers) for the respective routes. For example, actionNewPost will be called when handling at http://localhost:3000/default/new-post.

The last line contains the initialization of static class variables and bind to the module.


const Base = require('areto/base/Controller');
module.exports = class DefaultController extends Base {

  actionIndex () {
    this.send('<h1>Hello blog!</h1>');

Server restart

Start the web server. You will see the welcome at http://localhost:3000/default/index.