Playwright + JS · Lesson 8 of 35

0/35 done

Module 8: Node.js & npm Basics

8. Node.js & npm Environment for Playwright

13 minlesson

Try it yourself

Implement getEnvironmentConfig:

  1. Accept env object containing BASE_URL and HEADLESS.
  2. Return { baseUrl: env.BASE_URL ?? "https://targetqa.com", headless: env.HEADLESS === "true" }.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Node.js & package.json in Test Projects

json
{
  "name": "playwright-automation",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "test": "playwright test",
    "test:headed": "playwright test --headed",
    "test:ui": "playwright test --ui",
    "report": "playwright show-report"
  },
  "devDependencies": {
    "@playwright/test": "^1.49.0",
    "dotenv": "^16.4.5"
  }
}

Environment Variables (.env)

bash
BASE_URL=https://staging.targetqa.com
HEADLESS=true

Key Takeaways & Walkthrough Summary

Playwright runs on top of the Node.js JavaScript runtime. In this lesson, we will explore Node.js, npm, package.json, npm scripts, and managing environment variables using .env files for automation configurations. Let's explore!

Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why add '"type": "module"' in package.json?

It tells Node.js to use standard ES modules (import/export syntax) instead of legacy CommonJS (require).

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

JavaScript
Skip