Node is not created, but nid is returned I have this code in my module.

  $node = new stdClass();
  $node-&gt;title = "YOUR TITLE";
  $node-&gt;type = "page";
  node_object_prepare($node);

  $node-&gt;language = 'it';
  $node-&gt;uid = 1; 
  $node-&gt;status = 1;
  $node-&gt;promote = 0;
  $node-&gt;comment = 1;

  $node = node_submit($node);
  node_save($node);

  return "Nodo 222: " . $node-&gt;nid;


When I execute this code, it returns "Nodo 222: XXX," where XXX is an integer. If I execute it another time, I get XXX+1. When I try to load node/XXX or node/XXX+1, Drupal give me a Page not found error. 

I have seen the "node" table in MySQL (via PHPMyAdmin), and nids XXX and XXX+1 are not present. When I create a page via node/add/page, the new nid is XXX+2 and it is saved in the "node" table too. 

I have some modules installed (commerce, rules, logintoboggan and others), but this is the first time that I see this strange behavior.

So, where is my error?
Hope this will help you,

In Drupal 7, The $node object you pass to node_save() wouldn't get it's nid member populated unless the node has been successfully saved to the node table in the database.

The auto-increment ID actually comes from the database table so if the $node object has a nid, you can pretty much guarantee the record has been successfully inserted into the table.

Im just guessing check for "node" table paging.

Clear drupal cache and check again.

I have used the below code and it is working fine for me, you can refer this.

  $node = new stdClass();
  $node->type = "page";
  node_object_prepare($node);
  $node->title = 'test node';
  $node->language = 'it';
  // Set node body details
  $node->body[LANGUAGE_NONE]['0']['value'] = 'test body';
  $node->body[LANGUAGE_NONE][0]['summary'] = text_summary('test body');
  $node->body[LANGUAGE_NONE][0]['format'] = 'filtered_html';
  //.. other fields goes here
  $node->uid = 1;
  $node->status = 1;
  $node->promote = 0;
  $node->comment = 1;
  if ($node = node_submit($node)) {
    node_save($node);
    drupal_set_message('NODE : ' .$node->nid);
  }