Build a blog with Areto Framework

Primary init

In most applications, after installation, you must make an primary database initialization. It is necessary to add an administrator and other params. Start initialization by a separate script.


(async ()=> {
  const SystemHelper = require('areto/helper/SystemHelper');
  const Migrator = require('areto/db/Migrator');
  const Application = require('../Application');
  const application = new Application;
  try {
    const data = SystemHelper.parseArguments(process.argv);
    await application.init();
    const migrator = new Migrator({module: application});
    await migrator.migrate(data.action, data.file);
  } catch (err) {
    application.logError('Migration error', err);

Create the migrations directory and add the Init class to it. The class will create the Administrator user with the admin role. In the future, administrator can sign in to the application control module and create other users by the web interface.


const Base = require('areto/db/Migration');
module.exports = class Init extends Base {
  async apply () {
    await this.getDb().createIndex('user', [{email: 1}, {unique: true}]);
    const user = this.spawn(User);
      name: 'Administrator',
      email: 'a@a.a',
      role: 'admin',
      password: '123456'

You can run the script either from the command line, go to the blog directory:

node console/init.js apply migrations/Init

Either using Visual Studio Code:

Name: Init Areto Blog
Working directory: areto-blog
Javascript file: console/init.js
Application parameters: apply migrations/Init