使用 Web 服务器外部的模型航行 js [英] Sails js using models outside web server

查看:39
本文介绍了使用 Web 服务器外部的模型航行 js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 cli 来创建管理员用户 我在 api/models/User.js 中设置了用户模型

I want to create a cli to create admin users I have the user model setup in api/models/User.js

并在 cli 上

var User, program;

program = require("commander");

User = require("../api/models/User");

program.version("0.0.1");

program.command("create_user").description("Create a user into database").action(function() {
  return console.log(User);
});

program.parse(process.argv);

用户日志是:

    User = {
      attributes: {
        username: "string",
        password: "string",
      }
    };

并且没有可用的水线方法.

and no waterline methods available to use.

推荐答案

您可以使用sails run .

简单地用这个内容创建/commands/index.js:

Simply create <appPath>/commands/index.js with this content:

module.exports = {
    testcommand: function (done) {
        // .. your code
        console.log('this is my testcommand');
        done();
    }
}

现在你可以运行 sails run testcommand

这篇关于使用 Web 服务器外部的模型航行 js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆