How to duplicate nodes programmatically? I want to create duplicate nodes of a content type programmatically.

Is there any way to do this?

Note: I don't want to use any module to do this.
You can read the values from the original node in an array and create a new node with the data:

$storage = \Drupal::entityTypeManager()-&gt;getStorage('node');

$node = $storage-&gt;load($nid);

$original_values = $node-&gt;toArray();

// assign content type as string, the array causes an error when creating a new node
$original_values['type'] = $node-&gt;bundle();

// change title
$original_values['title'] = $node-&gt;label() . ' (cloned)';

// remove nid and uuid, the cloned node is assigned new ones when saved
unset($original_values['nid']);
unset($original_values['uuid']);

// remove revision data, the latest revision becomes the only one in the new node
unset($original_values['vid']);
unset($original_values['revision_translation_affected']);
unset($original_values['revision_uid']);
unset($original_values['revision_log']);
unset($original_values['revision_timestamp']);

$node_cloned = $storage-&gt;create($original_values);
$node_cloned-&gt;save();