Skip to content

Application console

Talysson de Oliveira Cassiano edited this page Mar 28, 2017 · 1 revision

Similar to Rails console and Laravel tinker, this boilerplate has a console implementation as well, that can even be used in production with stuff like heroku run.

You can run it with npm run console, by default it'll run in development mode, if you want to change the environment mode set a NODE_ENV environment variable for the command, like: NODE_ENV=test npm run console.

The implementation is pretty simple, it's just an extension of the common Node REPL but more promise-friendly (if the return of a command is a promise, the REPL will wait for it to be resolved/rejected instead of logging the promise instance), and it exposes the dependency injection container as the container variable, so you can type const UserModel = container.resolve('UserModel') in the REPL and it'll give you the Sequelize User model so you can query the database using the ORM directly from the command line.

If you want to expose other variables to the console scope, just pass them to the expose attribute of the console.

You can’t perform that action at this time.