Nest-cli: Custom Command Options while starting the app

Created on 6 Jan 2020  路  5Comments  路  Source: nestjs/nest-cli

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


Doesn't accept extra command options/parameters when starting the app.

error: unknown option {....}

Expected behavior


Should be allowed custom parameters.

Minimal reproduction of the problem with instructions

nest start --workers=2

What is the motivation / use case for changing the behavior?

Imagine your program requiring some extra options/parameters to be passed and used in main.ts.

For eg. Using the package express-cluster to run more than 2 workers of the app.

In the above case, I'd like to pass the no. of workers I want to run.

Suggestion:
Allow an array of custom options/parameters to be added to nest-cli.json and send those options to the handler before building.

Environment

[System Information]
OS Version     : macOS Catalina
NodeJS Version : v10.13.0
YARN Version    : 1.19.2

[Nest Information]
platform-express version : 6.7.2
mongoose version         : 6.1.2
passport version         : 6.1.1
common version           : 6.7.2
config version           : 0.0.7
core version             : 6.7.2
jwt version              : 6.1.1

Please let me know if the above suggestion makes sense. I'll make a PR for the same. If you have something better in mind, I'm all ears and ready to make a PR for it if possible 馃槃

Most helpful comment

Can you try nest start -- --workers=2 ?

All 5 comments

nest start -e "node --workers=2"

This reply is wrong. Ignore 馃槥

@kamilmysliwiec Getting this when I try the above

/usr/local/bin/node: bad option: --customOption

Can you try nest start -- --workers=2 ?

@kamilmysliwiec I am trying this in a docker container with yarn. This is what I get.

image

^ output of yarn seed -- --truncate

{
  scripts: {
    // ......
    "seed": "nest start -c nest-cli-seeder.json",
    "seed:truncate": "nest start -c nest-cli-seeder.json -- --truncate"
    "seed:custom": "nest start -c nest-cli-seeder.json --"
  }
}

seed:truncate & seed:custom --truncate works but not adding -- --truncate to just seed. Guess, it's a limitation to using yarn in this case.

Thanks a lot for all the help! 馃槃 馃憤

Yarn removes the first -- and sends down the rest, so you'd need one more --

yarn seed -- --truncate in your example would call nest start -c nest-cli-seeder.json -- --truncate

Was this page helpful?
0 / 5 - 0 ratings