I use a development folder that OneDrive doesn't back up and a backup folder OneDrive does back up and copy the development folder to the backup folder with a batch file. The following is essentially an example / step-by-step of @RanST's answer.
Create a batch file.
@ECHO ON
ECHO Copy started.
robocopy "{{SOURCE}}\PROJECTS" "{{DESTINATION}}\PROJECTS" /xd node_modules .serverless /s /z /r:3 /w:10 /tbd /np /ts
ECHO Copy completed!
PAUSE
/xd = exclude. Simply add the folder names to exclude.
/s = include subfolders exclude empty directories.
/z = retryable. /r:3 = 3 retries. /w:10 = wait 10 secs between retries.
/tbd = wait for a share names if they caused a retry error
/np = don't display progress
/ts = add a timestamp to the log
The Microsoft Documentation explains all the options.
Sync the parent.
I wanted a backup that didn't need to be updated every new project, so I chose to back up a parent folder and maintain the file structure when I created the development specific folders.
Main synced folder
/MY_WHOLE_BACKUP/.../PROJECTS/clients/client1/parentProject/subProject/root/myApp/app.js
DON'T simplify the path
/MY_LOCAL_FILES/.../PROJECTS/client1/myApp/app.js
DO keep it all
/MY_LOCAL_FILES/.../PROJECTS/clients/client1/parentProject/subProject/root/myApp/app.js
Schedule the task.
Search for and open the Task Scheduler in Windows.
Click Create Task....
Name the task.
Click the Triggers tab.
Click the New... button.
Adjust the schedule to your preference.
Click OK.
Click the Actions tab.
Click the New... button.
Browse for your batch file.
Click OK.
BOOM!
Test and configure as needed. I hope this helps.