node.jsrailway.js

How to add users in RailwayJS?


I'm using RailwayJS, a Node.JS MVC framework based on ExpressJS, fully ExpressJS-compatible. I'm trying to figure out how to add/generate users, but couldn't find any documentation about it. Does anybody know how?


Solution

  • Do you mean on application startup?

    In that case just define a user.js file under /config/initializers initi your model set the properties and save your model

    as example this is how my /config/initializers/user.js looks like

    var user;
    user = new User;
    user.username = "bob";
    user.password = "secret";
    user.email = "bob@example.com";
    user.displayName = "Bob";
    user.activated = true;
    user.createdAt = new Date();
    user.locale = "en";
    user.save();
    
    User.all(function(err, users) {
      var user, _i, _len, _results;
      _results = [];
      for (_i = 0, _len = users.length; _i < _len; _i++) {
        user = users[_i];
        _results.push(console.log(user));
      }
      return _results;
    });
    

    The last statement is just for logging the users that are loaded