javascript - Run several javascript file dynamically using same npm run command
问题描述
My folder structure:
app
Model
user.js
post.js
My package.json file
"scripts": {
"migrate": "node ./app/Model/"
}
I want to run javascript file in command line dynamically.
Like:
npm run migrate user.js
npm run migrate post.js
Is there any way to achieve this?
解决方案
You could write a script that dynamically requires the decired js file.
"scripts": {
"migrate": "node model.js"
}
Then model.js
like this:
const path = require('path');
require(path.join(__dirname, 'app', 'Model', process.argv[2]));
推荐阅读
- vba - 如何将共享邮箱电子邮件移动到与收件箱同级的文件夹中?
- php - 使用 phpcs for VSCode,如何根据它违反的规则集更改错误的字体颜色?
- reactjs - 如何查看函数中的状态?使用钩子
- laravel - 在 siteground 路线上上传 laravel 不起作用
- azure - 如何使用 adf 重命名文件,因为它们被复制到新位置
- typescript - 使用 TypeScript,我如何扩展可以是多种类型之一的接口?
- linux - 如何仅为当前会话设置 vi 选项?
- c++ - STM32H7 External Loader 无法通过 ST link 访问外部存储器
- sql - 更新访问表列出了给定的两组之间的所有数字
- django - Django - 如何将下拉表单更改为表格