A command-line tool to export content models and data from Contentful spaces.
-
Install dependencies:
npm install
-
Create environment file:
cp .env.example .env
-
Edit
.envwith your Contentful credentials:CONTENTFUL_SPACE_ID=your_space_id_here CONTENTFUL_MANAGEMENT_TOKEN=your_management_token_here CONTENTFUL_ENVIRONMENT_ID=master
# Export everything (models + content)
node index.js
# Or use npm scripts
npm run export# Export only content models (no content entries)
node index.js --models-only
npm run export:models
# Export only content entries (no models)
node index.js --content-only
npm run export:content
# Custom export directory
node index.js --export-dir ./my-exports
# Include validation rules in content models
node index.js --models-only --include-validation
# Skip specific data types
node index.js --skip-assets --skip-webhooks --skip-roles
# Use different environment
node index.js --environment staging
# Override credentials via command line
node index.js --space-id abc123 --token CFPAT-xyz| Option | Short | Description | Default |
|---|---|---|---|
--export-dir |
-d |
Export directory | ./export |
--models-only |
Export only content models | false |
|
--content-only |
Export only content entries | false |
|
--skip-content |
-c |
Skip content entries | false |
--skip-assets |
-a |
Skip assets | false |
--skip-roles |
-r |
Skip roles | false |
--skip-webhooks |
-w |
Skip webhooks | false |
--include-validation |
-v |
Include content type validation | false |
--environment |
-e |
Environment ID | master |
--space-id |
-s |
Space ID (overrides .env) | From .env |
--token |
-t |
Management token (overrides .env) | From .env |
--help |
-h |
Show help | |
--version |
-V |
Show version |
node index.js --models-only --include-validationnode index.js --export-dir ./backups --skip-assets --skip-webhooksnode index.js --environment staging --models-onlynode index.js --space-id different-space --token CFPAT-different-tokenThe tool will create timestamped JSON files in your export directory:
contentful-export-{spaceId}-{environment}-{timestamp}.json
- Never commit your
.envfile to version control - The
.envfile is already included in.gitignore - Use the
.env.examplefile as a template for team members
npm run export- Basic exportnpm run export:models- Export only content modelsnpm run export:content- Export only content entriesnpm run help- Show help information