NestJS Logo

Global prefix

To set a prefix for every route registered in an HTTP application, use the setGlobalPrefix() method of the INestApplication instance.


const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('v1');

You can exclude routes from the global prefix using the following construction:


app.setGlobalPrefix('v1', {
  exclude: [{ path: 'health', method: RequestMethod.GET }],
});

Alternatively, you can specify route as a string (it will apply to every request method):


app.setGlobalPrefix('v1', { exclude: ['cats'] });
Hint The path property supports wildcard parameters using the path-to-regexp package. Note: this does not accept wildcard asterisks *. Instead, you must use parameters (:param) or named wildcards (*splat).

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.

Principal Sponsors

Trilon LogoMarblism LogoMojam LogoAmplication Logo

Sponsors / Partners

Become a sponsor