Drupal 8: Programatically create Node with example

In Drupal 8, the node is an entity. The Drupal core class Node will provide us to create or update the nodes in Drupal 8. The below is the syntax with an example of creating a node Drupal 8.

Syntax: 

use Drupal\node\Entity\Node;
 
$nodeObj = Node::create([
  'type' => CONTENT_TYPE,
  'title' => TITLE,
  'body' => BODY_TEXT,
  'FIELD_1' => VALUE_1,
  'FIELD_2' => VALUE_2,
  'uid' => AUTHOR_UID,
]);
 
$nodeObj->save(); // Saving the Node object.
$nid = $nodeObj->id(); // Get Nid from the node  object.

Example: 

use Drupal\node\Entity\Node;
 
$nodeObj = Node::create([
  'type' => 'article',
  'title' => 'Programatically created Article',
  'body' => "CodeExpertz is contains best Blogs.",
  'field_date' => '2017-10-24',
  'field_category' => 'Study',
  'uid' => 1,
]);
 
$nodeObj->save(); // Saving the Node object.
$nid = $nodeObj->id(); // Get Nid from the node  object.
Print "Node Id is " . $nid;
Category: