Welcome, Guest Login

Public Cloud Center

File Storage

Last Updated: Jul 06, 2015 12:44PM EDT

Every Modulus application has several options for reading and writing files to disk. This article will cover these options in detail and show you how to utilize them in your projects.

Local Storage

There are two places to store information locally on each Servo. Your application directory and a temporary folder. All combined there is a 2GB limit on local storage, which includes the size of your application bundle.

Each instance of your application has its own local storage, meaning data cannot be shared between instances in a multi-Servo environment (this is what Cloud Storage is recommended for). Data stored in local storage may also be lost between project deploys.

There is no added charge for saving data to local storage.

Application Directory

Every folder within your application bundle is writable. This is useful for things like generated CSS and caching data. The application directory is not in a fixed location on each Servo, so it is recommended you make use the __dirname global variable when determining where to read and write information.

Example usage:

var fs = require('fs'),
    path = require('path');

// Save a file to the same directory as the current Node JavaScript file.
var filename = path.join(__dirname, 'example.txt');

// Write 'Hello World' to the file.
fs.writeFile(filename, 'Hello World', function(err) {

  // When complete, read the file back and print it to the console.
  fs.readFile(filename, 'example.txt'), function(err, data) {
    console.log(data); // Hello World
  });
});

Temporary Storage

Location: /mnt/temp/
Environment Variable: TEMP_DIR

The temporary folder is a convenient place to read and write temporary information. Your application has full read/write privileges to this directory.

Example usage:

var fs = require('fs'),
    path = require('path');

// Save a file to the temp folder.
var filename = path.join(process.env.TEMP_DIR, 'example.txt');

// Write 'Hello World' to the file.
fs.writeFile(filename, 'Hello World', function(err) {

  // When complete, read the file back and print it to the console.
  fs.readFile(filename, 'example.txt'), function(err, data) {
    console.log(data); // Hello World
  });
});

Cloud Storage

Location: /app-storage
Environment Variable: CLOUD_DIR
 

This feature has been deprecated and is no longer recommended for production applications. We are actively replacing the implementation with a much more robust system. In the meantime we recommend using AWS S3 or Joyent Manta for persistent storage needs.

Cloud Storage acts like a directory on disk and can be read and written to normally. All data stored in this directory will persist for the life of your project, even between starts, stops, and re-deploys.

Data stored here is also shared between every instance of your application. Meaning in a multi-Servo environment, if one instance writes data to this directory, all other instances immediately gain access to that data.

Data saved here is charged on a per-gigabyte basis and there is no limit to the amount that can be stored.

Example usage:

var fs = require('fs'),
    path = require('path');

// Save a file to the cloud directory.
var filename = path.join(process.env.CLOUD_DIR, 'example.txt');

// Write 'Hello World' to the file.
fs.writeFile(filename, 'Hello World', function(err) {

  // When complete, read the file back and print it to the console.
  fs.readFile(filename, 'example.txt'), function(err, data) {
    console.log(data); // Hello World
  });
});
Go to top
 

Contact Us

    Our Support Policy
    Submit a Support Request

  • Public Cloud Support Hours
    9am-5pm EST Mon-Fri
    Outside of these hours response times may be up to 24hrs.


    Submit a support ticket by clicking 'status and support' icon on the left side of this page.



help@hellotangible.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en_us/portal/articles/autocomplete