A. L
A. L

Reputation: 12649

MacOS: Pass filepath into node via cli

Say I have the following npm script:

"test": "node $FILE"

How would I pass an absolute path to it via cli?

Example:

FILE="pwd + filename" npm run test

which should result in:

node /Root/Subfolder/filename

I'm on MacOS using NodeJS 14.

Upvotes: 0

Views: 306

Answers (1)

Azeem
Azeem

Reputation: 14627

For example, you have a script file e.g. ./scripts/test.js.

The script config would be like this:

"test": "node ${FILE}"

And, the command to run it would be:

$ FILE="$(pwd)/scripts/test.js" npm run test

Upvotes: 1

Related Questions