I want to create a cli to create admin users I have the user model setup in api/models/User.js
and in cli on
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 log is:
User = {
attributes: {
username: "string",
password: "string",
}
};
and no waterline methods available to use.
Sails is the most popular MVC framework for Node. js, designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture.
Waterline: SQL/noSQL Data Mapper (ORM/ODM) Sails comes installed with a powerful ORM/ODM called Waterline, a datastore-agnostic tool that dramatically simplifies interaction with one or more databases.
Create your app Empty · An empty Sails app, yours to configure (type "?" for help, or <CTRL+> to cancel) ? Type 1 (or press enter) to start with our "Web App" template: an opinionated starter project that includes essential features like login, password recovery, emails, and billing.
You can use sails run <command>
.
Simply create <appPath>/commands/index.js
with this content:
module.exports = {
testcommand: function (done) {
// .. your code
console.log('this is my testcommand');
done();
}
}
now you can run sails run testcommand
If any one needs this:
sails = require("sails");
sails.lift({
log: {
level: 'silent'
}
}, function() {
User.create(obj);
process.stdin.destroy();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With