Add bootstrap.inc to file to programatically save nodes
Drupal 7 uses the DRUPAL_ROOT constant that is set to the Drupal root directory path. If you look at the code of the index.php file, you will notice the following code.

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();


The constant is also used from Drupal functions, such as module_load_include().

  if (function_exists('drupal_get_path')) {
    $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
    if (is_file($file)) {
      require_once $file;
      return $file;
    }
  }


If you have to write, for any reason, a function similar to module_load_include() you should use DRUPAL_ROOT to get the Drupal root directory.

Supposing that in your case Drupal is not in the current directory, you can use the following code.

define('DRUPAL_ROOT', 'the directory containing Drupal');

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);