Use dotenv in playwright node.js server

In order for dotenv to work, you need to add import “dotenv/config“; in playwright.config.js

Then in your test script import * as dotenv from 'dotenv'; in example.spec.ts

to call the environment variables:
const API_USER_ID: string = process.env.API_USER_ID || 'user_api';
const API_USER_PASSWORD: string = process.env.API_USER_PASSWORD || 'xyz-123';

Create .env with your environment variables:
USER_ID = user_api
API_USER_PASSWORD = xyz-123