How Can I Pass a Custom Flag to the 'nx angular serve' Command Without Encountering an Error?

25 Views Asked by At

I wish to include my custom flag (-t example) when executing the nx angular serve command.

However, I encounter an error from nx indicating:

't' is not found in schema

I intend to intercept this flag within proxy.mjs and handle it accordingly.

What steps should I take to pass this argument without encountering an error?

1

There are 1 best solutions below

2
Get Off My Lawn On

You can pass environment variables to ng serve using ENV t=xxx where xxx is the value you want.

ENV t=123 ng serve

You can then retrieve the value via process.env:

const { t } = process.env;
console.log(t); 

// Logs (string): 123

For multiple variables, you just use multiple ENV commands:

# All three ways seem to work:

ENV t=123 ENV u=abc ng serve
ENV t=123 u=abc ng serve
t=123 u=abc ng serve

Then logging would be the same:

const { t, u } = process.env;
console.log(t); 
console.log(u); 

// Logs (string): 123
// Logs (string): abc