[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/ssr/node/isMainModule [Back]  [Original]

isMainModule Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/ssr/node

isMainModule

function

Determines whether the provided URL represents the main entry point module.

On this page

    arrow_upward_alt Back to the top

    API

    function isMainModule(url: string): boolean;
    @paramurlstring

    The URL of the module to check. This should typically be import.meta.url.

    @returnsboolean

    true if the provided URL represents the main entry point, otherwise false.

    Description

    Determines whether the provided URL represents the main entry point module.

    This function checks if the provided URL corresponds to the main ESM module being executed directly. It's useful for conditionally executing code that should only run when a module is the entry point, such as starting a server or initializing an application.

    It performs two key checks:

    1. Verifies if the URL starts with 'file:', ensuring it is a local file.
    2. Compares the URL's resolved file path with the first command-line argument (process.argv[1]), which points to the file being executed.
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page