It essentially boils down to writing an app that creates / copies files and directories, adding some custom data to some of them. Most of the things you need to achieve that can be found in the file system module.
You could take a look at the source code to the express app to see how they do it.
Alternatively you could look at Yeoman, which covers this (and a few other things) in a more generic way. The specific bit for setting up a new project from a template is a generator and they have instructions on how to write your own.