Computer scienceBackendNode.jsWeb Development with Node.js

fetch API in Node.js

Creating a new user

Report a typo

Your task is to replace the blanks in the fetch options to correctly configure the request for creating a new user.

Fill in the gaps with the relevant elements
async function createUser(userData) {
  const response = await fetch('https://api.example.com/users', {
    : 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    : JSON.stringify(userData),
  });

  const data = await response.json();
  console.log('Created User:', data);
}

const newUser = {
  name: 'Jane Doe',
  email: '[email protected]',
};

createUser();

Create a free account to access the full topic