Skip to content
Learn with RV – Tech Blog
Learn with RV – Tech Blog

#testautomation #qa #programming #linux #devops

  • Home
  • Who am I?
  • 1-on-1 Mentoring
  • Test Automation Incubator
  • 24 Testimonials
  • YouTube
  • LinkedIn
  • Contact
Learn with RV – Tech Blog

#testautomation #qa #programming #linux #devops

July 3, 2026July 3, 2026

Using npm –prefix to Run Scripts from a Nested package.json

npm has an interesting flag called --prefix that can be useful when you have multiple package.json files in the same project.

A practical example is the following structure:

project-root/ 
package.json
tests/ package.json

In the project root, you may have a package.json dedicated to development-related packages, such as build tools, linting, formatting, or other general project scripts.

Separately, the project may contain a tests folder with its own package.json, dedicated to test-related packages. For example, this is where you might keep dependencies and scripts for Playwright, Cypress, or other automated testing tools.

Both package.json files can define their own scripts.

For example, in tests/package.json, you might have:

tests-pw

A commonly used approach, when running the command from the project root, is:

cd tests && npm run e2e

This works, but it requires changing the current directory before running the script.

An alternative approach is to use --prefix directly from the project root:

npm --prefix tests run e2e

In the example above, tests is the path to the folder that contains the target package.json, and e2e is the script defined inside tests/package.json.

In other words, you are telling npm: “run this command in the context of this folder.”

One benefit is that you can also expose this from the root package.json:

Then, from the project root, you can simply run:

npm run e2e

and npm will execute the e2e script defined in tests/package.json.

It is a small detail, but a useful one, especially in projects where automated tests are organized as a separate sub-project with their own dependencies and scripts.

Enjoyed this article?
I share more practical automation tips on YouTube and LinkedIn.

Need structured guidance instead of learning alone?
I offer 1-on-1 mentoring – learn more → HERE

Or email me at iamqarv [at] gmail [dot] com

Post Views: 6

Related

Share this article:
Programming

Post navigation

Previous post

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Using npm –prefix to Run Scripts from a Nested package.json
  • Unit Testing in JavaScript: Getting started with Vitest
  • Fail Fast in Playwright with maxFailures
  • Cleaner asserts in Grafana k6 load tests using expect
  • AI: What Happens When an AI’s Context Window Gets Full?

Recent Comments

  1. Paul on Web Accessibility: A step-by-step guide to Testing with pa11y
  2. Automated Tests for website Accessibility with Axe and TestCafe - Learn with RV - Tech Blog on How to generate E2E TestCafe Framework in seconds
  3. RV on Exploring Faker.js: A Powerful Tool for Generating Realistic Random Test Data
  4. Adrian Maciuc on Exploring Faker.js: A Powerful Tool for Generating Realistic Random Test Data
  5. Nick on Cypress vs Playwright vs Testcafe – which framework is faster?

Archives

  • July 2026
  • June 2026
  • May 2026
  • April 2026
  • March 2026
  • February 2026
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • March 2025
  • February 2025
  • January 2025
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023

Categories

  • AI
  • k6
  • Linux
  • Programming
  • QA
  • Tools
  • Uncategorized
©2026 Learn with RV – Tech Blog | WordPress Theme by SuperbThemes