How to create a node in Drupal 7 with a custom nid I have to create a node in drupal 7 with a custom nid but the solution I've tried doesn't works (The created node not appears in the backend). 
If I create the same node without the custom nid, it works.

Code:

$node = new stdClass();

$node-&gt;nid = intval($insert['id']);
$node-&gt;vid = intval($insert['id']);
$node-&gt;uid = 1;
$node-&gt;type = 'nodetype';

$node-&gt;title = $insert['name'];
$node-&gt;created = time();
$node-&gt;changed = $node-&gt;created;
$node-&gt;promote = 0;
$node-&gt;sticky = 0;
$node-&gt;format = 2;
$node-&gt;status = 1;
$node-&gt;language = 'en';

$node-&gt;field_custom_1 = array('und' =&gt; array(array( 'value' =&gt; $insert['foo'] )));
$node-&gt;field_custom_2 = array('und' =&gt; array(array('value' =&gt; $insert['hello'])));
$node-&gt;field_custom_3 = array('und' =&gt; array(array('value' =&gt; $insert['world']))); 

if ($node = node_submit($node)) {
    node_save($node);       
    drupal_set_message(t("Node ".$node-&gt;title." : ".$node-&gt;nid." added correctly"));
}
else { 
    drupal_set_message(t("Node ".$node-&gt;title." added incorrectly"), "error");
}


What's wrong? Thanks
http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_save/7

I believe node_save() takes all the node edit form input and builds a new node with a node-&gt;id for you.

node_save() either tries to update an existing node, or give you a newly saved one. You want to set what NID it gives you back.

Assuming an SQL storage engine for Nodes. You'd have to pick a NID greater than the current SQL MAX(id) FROM {node} ...

You could then make a new node entity with entity_create( See Creating and Editing Entities Documentation ) just passing the bare parameters you want: NID, type, bundle.

Then you could do a node_load() and then a node_save() with your code above to actually build out the rest of the node ...

That's what I would try.