Javascript 从Heroku CLI运行脚本

Javascript 从Heroku CLI运行脚本,javascript,heroku,sequelize.js,yargs,heroku-cli,Javascript,Heroku,Sequelize.js,Yargs,Heroku Cli,我想通过Heroku CLI运行一个脚本。这只是一个使用Sequelize在postgressql数据库中创建用户的简单脚本。 以下是脚本: const argv = require('yargs').argv; const Sequelize = require('sequelize'); const sqlizr = require('sqlizr'); require('dotenv').load(); // Check params if (!argv.username) { thr

我想通过Heroku CLI运行一个脚本。这只是一个使用Sequelize在postgressql数据库中创建用户的简单脚本。 以下是脚本:

const argv = require('yargs').argv;
const Sequelize = require('sequelize');
const sqlizr = require('sqlizr');
require('dotenv').load();


// Check params
if (!argv.username) { throw new Error('username is required!'); }
if (!argv.password) { throw new Error('password is required!'); }
if (!argv.clientId) { throw new Error('client id is required!'); }

// Init db connection
const sequelize = new Sequelize(
  process.env.DB_DATABASE,
  process.env.DB_USER,
  process.env.DB_PASS,
  {
    host: process.env.DB_HOST,
    port: 5432,
    dialect: 'postgres',
    logging: false
  }
)

var client_id = argv.clientId;
if(argv.clientId === -1){
  client_id = 0;
}

console.log(sequelize)

sqlizr(sequelize, 'api/models/**/*.js');

// Check if user exists
console.log('Check is user exists...');
sequelize.models.USERS.count({
  where: {
    USERNAME: argv.username
  }
})
  .then(result => {
    if (result > 0) {
      console.error('user already exists!');
      process.exit(1);
    }
  })
  .then(() => {
    console.log('Creating user...');
    sequelize.models.USERS.create({
      USERNAME: argv.username,
      PASSWORD: argv.password,
      CLNT_ID: client_id,
      EMAIL: 'email@email.com',
      PHONE: '123456789'
    })
     .then(result => {
       console.log('User created successfully!');
      })
      .catch(error => {
        console.error('Could not create user!', error);
      })
      .finally(result => {
        process.exit(1);
      });
  });
如果我在本地执行此命令,一切都会顺利进行:

 node bin/createUser.js --username admin --password admin --clientId -1
但如果我尝试通过Heroku CLI这样运行此命令:

heroku run bin/createUser.js --username admin --password admin --clientId -1
我在候机楼看到这个:

bin/createUser.js: line 4: syntax error near unexpected token `('
bin/createUser.js: line 4: `const yargs = require('yargs');'

我搞不清楚我做错了什么。希望有人能帮我解释一下为什么会发生这种情况

您忘了在命令中指定
节点
,所以我怀疑Heroku试图像运行shell脚本一样运行
createUser.js

您可能需要安装node.js buildpack才能在Heroku上运行该程序,但请尝试:

heroku run node bin/createUser.js --username admin --password admin --clientId -1