Ignore node_modules in Dropbox

Node is notorious for generating a rather large number of files in the node_modules when running and npm install. I like to start my projects in Dropbox, which presents a problem with my computer tries to sync tens of thousands of files, sometimes every few minutes if I’m working on a new module for example.

The solution for this problem is to the the “selective sync” feature of Dropbox, however it’s easiest if you haven’t already installed all the module dependencies. First, you want to create your project folder – either a directory followed by npm init, or possibly an existing project from a git or other source code repository.

In this example I will clone my node developer-tools module, which installs binaries and other tools for development work. This module can be found on Github here: https://github.com/doublesharp/node-developer-tools. It will be cloned into the path ~/Dropbox/Workspaces/node-developer-tools. After the directory has been created, we will manually create a node_modules folder inside it.

mkdir -p ~/Dropbox/Workspaces
cd ~/Dropbox/Workspaces
git clone https://github.com/doublesharp/node-developer-tools.git
mkdir -p ./node-developer-tools/node_modules

Now we can exclude this folder from Dropbox sync before filling it up with thousands of tiny files.

1. Select the dropbox icon from you system bar

2. Select the gear icon, followed by Preferences…

dropbox-node-1

3. Choose the Account tab

4. Find the Selective Sync option and click Change Settings…

dropbox-node-2

5. Navigate to Workspaces/node-developer-tools and un-select node_modules

6. Click the Update button

dropbox-node-3

Now you can install the node modules without having the sync to Dropbox.

Unfortunately this needs to be set up for each Node project you want to work with, but the up front investment will save time down the road. Plus a little storage space.

You may also like...

2 Responses

  1. Adam Shaw says:

    Hey Justin, I actually implemented a solution to do this with Rsync and it works great. It has some added benefits in that it will work for all future node_modules directories, and also ignores everything that git ignores. I wrote a guide: https://arshaw.com/exclude-node-modules-dropbox-google-drive

    • Justin Silver says:

      Hi Adam, that is super smart. Originally I was using a desktop + laptop with my workspaces in Dropbox two way syncing between them. That let me work at either computer on the same project and have it all backed up at the same time, which is a lot less of an issue now that I mostly use my laptop. It did get me thinking about options for a two way sync though – have you looked at Unison as an alternative to rsync for bidirectional sync to the DropBox folder (and beyond)? I might play around with it if I get some time soon and will let you know if it make anything interesting happen. Cheers!

      PS – nice work on FullCalendar!

Leave a Reply

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