Create a content type node programmatically I have a content type called ip_range and i was trying to create a node programmatically . I tried the follows :

use \Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;
    $data = array(
      'type' =&gt; 'ip_range', 
      'title' =&gt; '192.168.7.100/24', 
      'field_ip_range_gw' =&gt; '192.168.7.100', 
      'field_ip_range_hidden' =&gt; '', 
      'field_ip_range_blocked' =&gt; '192.168.7.200', 
      'field_ip_range_access_type' =&gt; 'Blocked', 
      'field_ip_threshold' =&gt; '20', 
      'field_ip_range_sec_zone' =&gt; 'C2', 
      'field_ip_range_vlan_name' =&gt; 'Network58', 
      'field_ip_range_vlan_tag' =&gt; '4054', 
      'field_ip_range_comment' =&gt; 'Ip ranges from 192.168.7.100 to 192.168.7.255', 
    );
    $node = Drupal::entityManager()
      -&gt;getStorage('node')
      -&gt;create($data);

    $node-&gt;save();


But its not creating any . Any idea ?

UPDATE



Its creating the node . But its creating as anonymous user . So i cant see it in front end . That was the problem . How to create it as a admin user ?
Try this Code in MigrateContentController:

&lt;?php

namespace Drupal\migrate_contents\Controller;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;

class MigrateContentController extends ControllerBase {

 function migrateContent() {
 $updated = 0;
 $data = array(
   'type' =&gt; 'ip_range', 
   'title' =&gt; '192.168.7.100/24', 
   'field_ip_range_gw' =&gt; '192.168.7.100', 
   'field_ip_range_hidden' =&gt; '', 
   'field_ip_range_blocked' =&gt; '192.168.7.200', 
   'field_ip_range_access_type' =&gt; 'Blocked', 
   'field_ip_threshold' =&gt; '20', 
   'field_ip_range_sec_zone' =&gt; 'C2', 
   'field_ip_range_vlan_name' =&gt; 'Network58', 
   'field_ip_range_vlan_tag' =&gt; '4054', 
   'field_ip_range_comment' =&gt; 'Ip ranges from 192.168.7.100 to 192.168.7.255', 
 );
 $node = Node::create($data);
 $node-&gt;save();
 $updated++;

 return array(
   '#markup' =&gt; $updated,
 );
 }
}



  Inside your_module.routing.yml


migrate_contents.migrate_node:
  path: '/migrate-contents'
    defaults:
    _controller: 'Drupal\migrate_contents\Controller\MigrateContentController::migrateContent'
    _title: 'Migrate Contents'
  options:
    _admin_route: TRUE


Note: Clear the cache before proceeding.