I have installed Knex in my Node project and all is wonderful and great... so far...
Now I dig deeper into Knex and am confronted with migrations. All the docs I found talk about running commands like "knex migrate:latest", etc. What I get as a result when I try to run such commands from the (Windows) command line is an error telling me that 'knex' is an unknown command.
I am not a npm and Nodes expert, just enough to get the basics running. When digging into the knex node package I find some configuration for a cli.js file under a 'bin' section in the 'package.json'. I do not understand these configurations, even reading the npm documentation about this 'bin' section does not make it clearer to me.
So here my question: I am on Windows 10 and have installed a package like 'knex' local to my project. Knex comes with a cli. What do I need to do to call that cli from my console?
You can find client from
node_modules/.bin/knex
if you haven't installed knex globally (which I don't recommend).When you install packages locally to some directory, all the "bin" executables are linked automatically under
node_modules/.bin
. If you use these scripts from package.json scripts, npm automatically addsnode_modules/.bin
to path, so inside package json you don't have to refernode_modules/.bin/knex
but justknex
is enough.First type in "npx knex" to access options and commands available to the knex module. To be able to make use of the Knex cli that comes bundled with it, you then have to access the knex module from whatever path you intend creating the file from. For example, let's say I was in the migrations directory and the node_modules folder is one path higher, I would access the Knex module in it this way '../node_modules/.bin/knex migrate:make create-user-table.js' to be able to create a 'create-user-table.js', migration file. I hope I'm clear enough.