本文介绍了如何使用Knex CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Node项目中安装了Knex,到目前为止一切都非常好...

I have installed Knex in my Node project and all is wonderful and great... so far...

现在,我对Knex进行了更深入的研究,并面临迁移问题.我发现的所有文档都涉及运行"knex migration:latest"等命令.当我尝试从(Windows)命令行运行此类命令时,得到的结果是一个错误,告诉我'knex'是一个未知命令.

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.

我不是npm和Nodes专家,只是足以使基础知识得以运行.当深入研究knex节点包时,我在"package.json"的"bin"部分下找到了cli.js文件的一些配置.我不理解这些配置,即使阅读有关此"bin"部分的npm文档也不清楚.

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.

所以这是我的问题:我在Windows 10上,并且在我的项目本地安装了像'knex'这样的软件包. Knex附带了CLI.我需要怎么做才能从控制台调用该CLI?

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?

推荐答案

如果尚未全局安装knex(我不建议这样做),则可以从node_modules/.bin/knex查找客户端.

You can find client from node_modules/.bin/knex if you haven't installed knex globally (which I don't recommend).

在本地将软件包安装到某个目录时,所有"bin"可执行文件都将自动链接到node_modules/.bin下.如果您使用package.json脚本中的这些脚本,npm会自动将node_modules/.bin添加到路径中,因此在json包中您不必引用node_modules/.bin/knex,而只需knex即可.

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 adds node_modules/.bin to path, so inside package json you don't have to refer node_modules/.bin/knex but just knex is enough.

这篇关于如何使用Knex CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:26