---
schema_version: "1"
id: e04fb0c8c0e7f43ca72f0e086fa2edee66cf6e8e8cae010f7bd9d66075f69605
title: Project Configuration in LWR on Node.js
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwr-node/lwr/guides/lwr-configure-project.md
canonical_url: https://developer.salesforce.com/docs/platform/lwr/guide/lwr-configure-project.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9b13637303a3d8ffd8893fb17f1773a48519ad6f7efd964521f6328d0c5347e1
products:
  - Lightning Web Runtime
---
# Project Configuration in LWR on Node.js

LWR is built with customization and extensibility in mind.

You can customize both the server configuration and project setup for your LWR project. The LWR server is configured in `lwr.config.json`, at the root of the project. This page describes various `lwr.config.json` configuration options.

For other configuration options, such as adding dependencies to your project or customizing LWR’s module support, check out [Configure Packages and Modules](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-packages-modules.md).

## Understand lwr.config.json

The `lwr.config.json` file generated for your [initial StaticSite project](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-get-started.md) only has a few things happening:

- It provides a [module source directory](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-packages-modules.md#options-for-specifying-module-records) for LWC modules in your project repo.
- It specifies how to handle the [bundling](#configure-bundles) of the `lwc` module.
- It tells LWR how to [route](#configure-routes) to some pages.

```json
{
  "lwc": { "modules": [{ "dir": "$rootDir/src/modules" }] },
  "bundleConfig": { "exclude": ["lwc"] },
  "routes": [
    {
      "id": "Home",
      "path": "/",
      "contentTemplate": "$contentDir/home.md",
      "layoutTemplate": "$layoutsDir/main_layout.njk"
    },
    {
      "id": "About",
      "path": "/about",
      "contentTemplate": "$contentDir/about.md",
      "layoutTemplate": "$layoutsDir/main_layout.njk"
    },
    {
      "id": "Explore",
      "path": "/explore",
      "contentTemplate": "$contentDir/explore.md",
      "layoutTemplate": "$layoutsDir/main_layout.njk"
    }
  ]
}
```

You can do more with the lwr.config.json file, however. You can also [configure directory locations](#configure-directory-locations-and-lightning-web-security) of templates, global context data, and static assets, as well as set the [port, server type, and server mode](#configure-the-port-and-server).

## Configure Routes

Page routing for LWR projects is controlled in the `lwr.config.json` configuration file. This topic is covered in detail on the [Server-Side Routing in LWR page](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-routing-server.md).

## Configure the Port and Server

You can use `lwr.config.json` to access some LWR port and server configurations:

- `port`: The port from which to serve the LWR application. The default is `process.env.PORT || 3000`.
- `serverMode`: The mode in which to run the server. Mode is typically set on the [command line](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-get-started.md#set-the-lwr-server-modes). The default is `"dev"`. See available modes [here](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-get-started.md#set-the-lwr-server-modes).
- `serverType`: The type of underlying web server that LWR uses. Currently supported values are `"express"` (default) or `"koa"`.

For example:

```
{
    "port": 3333,
    "serverMode": "prod",
    "serverType": "express"
}
```

## Configure Directory Locations and Lightning Web Security

You can configure a variety of directory locations in your `lwr.config.json` file:

- `rootDir`: The root directory of the LWR project. The default is the current working directory (`.`).
- `cacheDir`: LWR caches LWC modules that it has compiled and stores them in a cache directory. The default is `"$rootDir/__lwr_cache__"`.
- `contentDir`: The content templates directory. The default is `"$rootDir/src/content"`.
- `layoutsDir`: The layout templates directory. The default is `"$rootDir/src/layouts"`.
- `globalDataDir`: The directory of [global data](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-compile-data.html#global-data) for templating. The default is `"$rootDir/src/data"`.
- `hooks`: A list of configuration hooks that you can use to dynamically alter the configuration and global data for your application on server startup. Hooks are an advanced topic and are not covered in detail at this point.
- `locker`: Allows you to enable [Lightning Web Security](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.security_lwsec_intro) and optionally configure a list of trusted components. By default, Lightning Web Security (LWS) is disabled. If LWS is on, components from LWC and LWR are automatically trusted.

**note:** The `locker` key actually configures LWS, not Lightning Locker. This setting is independent of the LWS setting that can be enabled for an org.

For example:

```
{
    "rootDir": "/Users/me/lwr/projects/awesome",
    "cacheDir": "$rootDir/build/cache",
    "contentDir": "$rootDir/templates",
    "layoutsDir": "$rootDir",
    "globalDataDir": "$rootDir/src/templateContext",
    "hooks": ["$rootDir/src/hooks/docs-app-hooks.js"],
    "locker": {
        "enabled": true,
        "trustedComponents": ["my/trustedCmp"]
    }
}
```

You can also configure directories to serve static assets. For more information, see [Template and Asset References](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-templates.md#template-and-asset-references) in [LWR Content and Layout Templates](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-templates.md).

## Configure Bundles

If a recipe is running in `prod` or `prod-compat` [mode](https://developer.salesforce.com/docs/platform/lwr/guide/lwr-get-started.md#set-the-lwr-server-modes), LWR bundles modules before sending them to the client. Depending on your project setup, the same module dependency can get pulled into more than one bundle. This doesn't cause a problem for most modules, but some must be treated as singletons.

Examples of such modules are `lwc`, `lwr/navigation`, and `@lwc/synthetic-shadow`. The solution is to put these modules in their own, shareable bundles. In the `lwr.config.json` file, `bundleConfig.exclude` excludes the module from bundling when modules are requested. If your application contains additional singleton modules, exclude them from bundling as well:

```
{
    "bundleConfig": {
        "exclude": ["my/singleton", "do/notBundle"]
    }
}
```
