Oct 21, 2025

Automate File Generation with n8n & Slack

Automate File Generation with n8n & Slack Learn how to build an automated n8n workflow that generates JSON data on a schedule, converts it to a binary file, writes it to disk, and notifies your team on Slack. This practical guide walks through each node, shows example code, and gives tips for production-ready automation. Why […]

Automate File Generation with n8n & Slack

Automate File Generation with n8n & Slack

Learn how to build an automated n8n workflow that generates JSON data on a schedule, converts it to a binary file, writes it to disk, and notifies your team on Slack. This practical guide walks through each node, shows example code, and gives tips for production-ready automation.

Why automate file generation?

Automating file generation saves time, eliminates manual errors, and ensures consistent formatting and delivery. Common use cases include exporting daily reports, backing up data snapshots, or producing files for downstream systems. With n8n, you can combine scheduling, lightweight code, binary conversion, and integrations like Slack in a single, visual workflow.

Overview of the example workflow

The example workflow contains five nodes:

  • Scheduled Trigger — runs every minute (or your chosen schedule)
  • Generate Example Data (Function) — creates the JSON payload to save
  • Convert To Binary (Function) — converts the JSON to a base64 binary property
  • Write File — saves the binary to a file on disk
  • Slack Notification — posts a message to a Slack channel indicating success

This flow is perfect for learning the pattern and can be extended to store files in cloud storage (S3, Google Drive), send email attachments, or trigger other services.

Step-by-step: building the workflow

1. Scheduled Trigger

Add the Scheduled Trigger node and set the cadence that suits you. For testing you might choose every minute, but for production you’ll likely pick hourly, daily, or a cron expression. The trigger starts the workflow and passes a single item downstream.

2. Generate Example Data (Function node)

Use a Function node to dynamically create the JSON you want to save. You can build complex objects, include timestamps, or fetch data from APIs before this step. Here’s the example code used in the demo workflow:

items[0].json = {
  "text": "asdf",
  "number": 1
};
return items;

Replace the static data with your real payload. For example, generate a daily report, attach metadata such as date or runId, or aggregate results from previous nodes.

3. Convert To Binary (Function node)

To write a file with the Write File node, n8n expects binary data. The Convert To Binary Function encodes your JSON as base64 and attaches it to the item’s binary property:

items[0].binary = {
  data: {
    data: Buffer.from(JSON.stringify(items[0].json, null, 2)).toString('base64')
  }
};
return items;

Notes:

  • Use Buffer.from(...).toString('base64') to avoid deprecation warnings with new Buffer.
  • You can name the binary property anything (here it’s data), but reference that name in the Write File node.

4. Write File

Configure the Write File node to use the binary data property you created. Set the fileName to a static name like test.json or build a dynamic filename using expressions (for example, report-{{$now.toISOString().slice(0,10)}}.json).

Consider file storage location and permissions. The Write File node writes to the n8n host file system by default. For shared or durable storage, use cloud integrations (S3, Google Drive) or mount a network volume.

5. Slack Notification

Finish the flow with a Slack node to alert your team. Send a concise message with the filename, timestamp, and optional link to the file or logs. Example message:

File written: test.json

Set up an incoming webhook or use a Slack app token to authenticate. Use Slack attachments or blocks to provide richer context when needed.

Testing and debugging

Run the workflow manually or set the schedule to a fast cadence while building. Use the n8n execution logs and node output inspector to verify each step. Common issues:

  • Binary property not found — confirm the property name in the Write File node matches the Function node.
  • Permissions error when writing files — check the file path and n8n container/user permissions.
  • Slack authentication failed — verify tokens and channel names.

Production considerations & best practices

Use dynamic filenames

Avoid overwriting files by using timestamps or unique IDs in filenames. Example expression for a daily file name:

report-{{$now.format('YYYY-MM-DD')}}.json

Store files in durable storage

For backups and long-term retention, write files to S3, Google Cloud Storage, or a dedicated file server. n8n has nodes or HTTP options to upload files directly, avoiding dependence on the n8n node host filesystem.

Add error handling and retries

Wrap critical steps in error workflows or use the “On Error” workflow trigger. For transient failures (network, API rate limits), implement retries with exponential backoff.

Monitor and log

Emit structured logs or create a monitoring workflow that reports failed runs to Slack or email. Keep executions concise and use scopes to avoid leaking sensitive data.

Extending the workflow

  • Upload generated files to AWS S3, then post a signed URL to Slack.
  • Attach files to emails using SMTP or transactional email providers.
  • Trigger downstream workflows by publishing a message to a message queue.

Security tips

  • Don’t store secrets in Function nodes. Use n8n credentials and environment variables.
  • Restrict file system access for the n8n process and rotate credentials used for cloud uploads.
  • Limit Slack scopes and create a dedicated bot user for notifications.

Complete example: minimal JSON workflow

Here’s a minimal n8n workflow snippet you can import and adapt. It creates a simple JSON file and notifies Slack after writing the file.

{
  "name":"Generate and Save Example File",
  "nodes":[ ... ]
}

(Use the n8n UI to import and customize the full workflow JSON.)

Conclusion

Generating and saving files with n8n is straightforward: schedule a trigger, create or gather data, convert it to binary, write it to disk or cloud, and notify your team. This pattern is flexible and can be extended into robust, production-ready automations.

Ready to get started? Import the example workflow into your n8n instance, customize the data and filename, and enable the schedule. If you need help adapting this pattern for S3, Google Drive, or advanced error handling, contact the n8n community or your automation team.

Call-to-action: Try this workflow now — import it into n8n, run a test, and post a message to Slack. Share your results or questions in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *