Create a node programmatically on installing a module I would like to have my module to create new nodes (page) when being installed and removing these pages on uninstall.

I tried the following with no success in my mymodule.install file:

&lt;?php

function mymodule_install() {

  $node = new stdClass(); // We create a new node object
  $node-&gt;type = "page"; // Or any other content type you want
  $node-&gt;title = "Your title goes jere";
  $node-&gt;language = LANGUAGE_NONE; // Or any language code if Locale module is enabled. More on this below *
  $node-&gt;uid = 1; // Or any id you wish
  $node-&gt;path = array('alias' =&gt; 'your_node_path'); // Setting a node path
  node_object_prepare($node); // Set some default values.

  // Let's add standard body field
  $node-&gt;body[$node-&gt;language][0]['value'] = 'This is a body text';
  $node-&gt;body[$node-&gt;language][0]['summary'] = 'Here goes a summary';
  $node-&gt;body[$node-&gt;language][0]['format'] = 'filtered_html'; // If field has a format, you need to define it. Here we define a default filtered_html format for a body field

  $node = node_submit($node); // Prepare node for a submit
  node_save($node); // After this call we'll get a nid  

}


This code is cut n' paste from this page.

When I disable/enable the module, the page is not created (at least it does not appear in Content and in the node table of the database).

How should I do it please?
The problem is that install/uninstall and enable/disable are two separate things in Drupal.

When you enable or disable a module, hook_enable() and hook_disable() are invoked respectively.

When you install or uninstall a module, hook_install() and hook_uninstall() are invoked respectively.

If you want to keep your code in hook_install() / hook_uninstall() you'll need to disable the module, and then uninstall it at http://mysite.com/admin/modules/uninstall. Once you re-install it (which will also enable it), your code will be run.

It might be worth having a think if this code would be better served in hook_enable() / hook_disable(), but it will depend on your particular situation.