7. ES Modules (import/export) & npm Configuration

ES Modules: Named vs Default Export

// Named export (constants.ts):
export const DEFAULT_TIMEOUT = 30000;
export const BASE_URL = "https://targetqa.com";

// Importing named exports:
import { DEFAULT_TIMEOUT, BASE_URL } from "./constants";

// Default export (LoginPage.ts):
export default class LoginPage { ... }

// Importing default export:
import LoginPage from "./LoginPage";

Environment Variables

In automation, URLs and credentials vary across environments (dev, staging, prod):
const targetEnv = process.env.TEST_ENV || "staging";

Task

  • Write an export statement exporting a constant named `API_TIMEOUT` set to `10000`.
πŸ’‘Common doubts
Did you like the problem?
Lesson 7 of 36
TypeScript
Loading code editor…
Next