title: Enable Cors in NestJs
body: <p>I want to use a NestJs api, but I get the same error message in each <code>fetch</code>:</p>
  <pre class="lang-none prettyprint-override"><code>Access to fetch at 'http://localhost:3000/articles' from origin 'http://localhost:4200' has been blocked by CORS policy: 
  No 'Access-Control-Allow-Origin' header is present on the requested resource.
  If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  </code></pre>
  <p>My frontend is an Angular, where I have a simple <code>fetch</code> :</p>
  <pre><code>fetch('http://localhost:3000/articles')
      .then((res) =&gt; {
        console.log(res);
      });
  </code></pre>
  <p>I tried these options in my NestJs - but none of them seem to work:</p>
  <p><strong>Attempt A</strong></p>
  <pre><code>async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.enableCors({
      origin: true,
      methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
      allowedHeaders: 'Content-Type, Accept',
    });
    await app.listen(3000);
  }
  bootstrap();
  </code></pre>
  <p><strong>Attempt B</strong></p>
  <pre><code>async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.enableCors();
    await app.listen(3000);
  }
  bootstrap();
  </code></pre>
  <p><strong>Attempt C</strong></p>
  <pre><code>async function bootstrap() {
    const app = await NestFactory.create(AppModule, {cors: true});
    await app.listen(3000);
  }
  bootstrap();
  </code></pre>