I'm currently developing multiple node.js programs that all fall under the same project. These programs will share common code for things like connecting to a server, inserting to a database, and even logging to console. Ideally, I'd like to package all of these under one parent program, like how git does it - users execute 'git [command]' to run the program 'git-[command]'.
The problem is that there are programs to be run on the server, and programs to be run on the client - I'd like to keep these separate. There are also multiple programs that every server and client will need, but I'd like to keep these separate as well instead of just having 'server' and 'client' packages.
Is there any documentation for what I'm trying to do? Or, if what I'm trying to do is not recommended, what would you guys suggest instead?
Thanks!
My suggestion is to create node packages of your common code and then use npm to install and handle dependencies, updates and so on.
You are probably used to installing npm packages from the official npm registry. They can also be installed using local folders as source:
From the documentation.
{
"name": "mainproject",
"dependencies": {
"serverstuff": "file:../foo/bar"
}
}
You can also install from GitHub:
{
"name": "mainproject",
"dependencies": {
"serverstuff": "https://github.com/user-xyz/baz/tarball/master"
}
}
The common code packages can also have their own dependencies:
{
"name": "serverstuff",
"dependencies": {
"connect": "file:../foo/bar2"
}
}