Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-deb

heartsucker3.9kMIT0.10.7

Debian packaging for Node.js projects

debian, ubuntu, deb, dpkg, package, packaging, upstart, systemd, system v

readme

node-deb

Debian packaging for Node.js projects written 100% in bash.

Simple.

Installation

npm install node-deb

or

git clone ${url} && cd node-deb && npm run node-deb && sudo dpkg -i $(find . -maxdepth 1 -type f -name '*.deb' | tail -n 1)

Usage

A simple project can be packaged with the following command.

node-deb -- index.js lib/

This command will add all of the above files and directories to a Debian package as well as generate the scripts necessary to install, uninstall, start, and stop your application. On installation, via dpkg -i $your_package_name, dedicated Unix users and groups will be created and your distribution's default init system will start and monitor the process.

node-deb uses sane defaults, so the only thing you need to add to your package.json is the app/cli entrypoint. However, if you don't like these, there are two options for overrides: command line options, or the JSON object node_deb at the top level of your package.json. A full explanation of the different options can be found by running node-deb --help.

By default, if any of the following files exist, they will be included in the Debian package: package.json, npm-shrinkwrap.json and package-lock.json.

For example, here are some sample node_deb overrides. The full list can be found by running node-deb --list-json-overrides.

{
  "name": "some-app",
  ...
  "node_deb": {
    "init": "systemd",
    "version": "1.2.3-beta",
    "entrypoints": {
      "daemon": "foo.js --config /etc/some-app/config.js"
    }
  }
}

Command line options always override values found in the node_deb object, and values found in the node_deb object always override the values found in the rest of package.json.

Examples

Ex. 1

package.json:

{
  "name": "some-app",
  "version": "1.2.3",
  "node_deb": {
    "entrypoints": {
      "daemon": "app.js arg1 arg2"
    }
  }
}

cmd: node-deb -- app.js lib/

You will get:

  • A Debian package named some-app_1.2.3_all.deb
    • Containing the files app.js & package.json and the directory lib
    • Installed via
      • apt-get install some-app
      • apt-get install some-app=1.2.3

On install, you will get.

  • An executable named some-app
    • That starts the app with the command app.js arg1 arg2 arg3
  • An upstart init script installed to /etc/init/some-app.conf
  • A systemd unit file installed to /lib/systemd/system/some-app.service
  • A sysv int script installed to /etc/init.d/some-app
  • A Unix user some-app
  • A Unix group some-app

Ex. 2

package.json:

{
  "name": "some-other-app",
  "version": "5.0.2",
  "node_deb": {
    "entrypoints": {
      "daemon": "index.js --daemon"
    }
  }
}

cmd: node-deb -u foo -g bar -v 20150826 -- index.js lib/

You will get:

  • A Debian package named some-other-app_20150826_all.deb
    • Containing the files index.js, package.json, & npm-shrinkwrap.json|package-lock.json and the directories lib & node_modules
    • Installed via
      • apt-get install some-other-app
      • apt-get install some-other-app=20150826

On install, you will get.

  • An executable named some-other-app
    • That starts the app with the command index.js --daemon
  • An upstart init script installed to /etc/init/some-other-app.conf
  • A systemd unit file installed to /lib/systemd/system/some-other-app.service
  • A sysv int script installed to /etc/init.d/some-other-app
  • A Unix user foo
  • A Unix group bar

Ex. 3

package.json:

{
  "name": "a-third-app",
  "version": "0.10.1",
  "node_deb": {
    "init": "none",
    "dependencies": "apparmor, tor",
    "templates": {
      "postinst": "my-teplates/my-postinst-template.txt"
    },
    "entrypoints": {
      "cli": "app.js"
    }
  }
}

cmd: node-deb -- app.js lib/

You will get:

  • A Debian package named a-third-app_0.10.1_all.deb
    • Containing the files index.js, package.json, & npm-shrinkwrap.json|package-lock.json and the directories lib & node_modules
    • With additional dependencies on apparmor and tor
    • Installed via
      • apt-get install a-third-app
      • apt-get install a-third-app=0.10.1
    • With the postinst script rendered from the template my-postinst-template.txt

On install, you will get.

  • An executable named a-third-app
    • That starts the app with the command app.js
  • No upstart, systemd, or sysv scripts
  • No Unix user or group

Ex. 4

package.json:

{
  "name": "a-forth-app",
  "version": "0.10.1",
  "node_deb": {
    "init": "none",
    "dependencies": "apparmor, tor, nodejs",
    "templates": {
      "postinst": "my-teplates/my-postinst-template.txt"
    },
    "entrypoints": {
      "cli": "app.js"
    }
  }
}

cmd: node-deb --no-default-package-dependencies -- app.js lib/

You will get:

  • A Debian package named a-forth-app_0.10.1_all.deb
    • Containing the files index.js, package.json, & npm-shrinkwrap.json|package-lock.json and the directories lib & node_modules
    • With dependencies on apparmor, tor and nodejs only. No default dependencies added
    • Installed via
      • apt-get install a-forth-app
      • apt-get install a-forth-app=0.10.1
    • With the postinst script rendered from the template my-postinst-template.txt

On install, you will get.

  • An executable named a-forth-app
    • That starts the app with the command app.js
  • No upstart, systemd, or sysv scripts
  • No Unix user or group

&c.

Note: Removal via apt-get purge will attempt to remove the user and group defined in the Debian package. This can have serious consequences if the user or group is shared by other applications!

node-deb can Debian-package itself. Just run npm run node-deb.

More complete examples can be found by looking at test.sh and the corresponding projects in the test directory.

Options

This section incldues addtional details about the more advanced functionality of node-deb

--install-strategy

The install strategy determines how dependencies in node_modules are included in the final Debian package.

  • auto: This attempts to take a minimal subset of package from the node_modules director using npm ls --prod. If this is not possible, it falls back to the copy method. On install, if node_modules is present, it runs npm rebuild --prod. If node_modules is not present, it runs npm install --prod. If npm is not present, it issues a warning that dependencies may be missing and continues with the Debian package installation.
  • copy: This runs a blind cp -rf on the node_modules directory and includes everything in the Debian package. No actions are taking during package installation.
  • npm-install: This option does not include the node_module in the Debian package and runs npm install --production as part of the postinst maintainer script.

Requirements

  • dpkg
  • fakeroot
  • jq

These are all available through apt and brew.

Dev Requirements

Tests are run via docker. This is also available through apt and brew.

Support

node-deb only officially supports the currently supported versions of Debian and Ubuntu (LTS). This includes both for building packages and deploying packages. At the time of this update, this translates to Debian Wheezy through Stretch and Ubuntu Trusty through Xenial. Care has been taken to ensure this packages correctly on macOS, and macOS specific issues should still be reported.

Contributing

Please make all pull requests to the develop branch.

Please make sure all pull requests pass the test suite locally.

changelog

CHANGELOG

0.10.7 2018-07-16

  • Added
    • --preinst-template CLI option and node_deb.templates.preinst for Debian preinst templates.
    • --install-dir CLI option and node_deb.install_dir for variable install locations (e.g., /opt/ instead of /usr/share/)
  • Fixed
    • Possible NPM related errors on install

0.10.6 2018-05-02

  • Fixed
    • Bug where Unix user/group names over 32 characters were accepted, thus breaking installs

0.10.5 2018-05-30

  • Fixed
    • Permissions errors during install for native builds
    • Incorrect quoting on app entrypoints

0.10.4 2018-02-20

  • Fixed
    • Error with sed commands on macOS

0.10.3 2018-02-05

  • Fixed
    • Typo prevented cleanup of symlinks.

0.10.2 2018-01-13

  • Added
    • no-default-dependencie flag to not include the dependency on nodejs and sudo.

0.10.1 2017-10-07

  • Removed
    • Creation/removal of Unix user/group for non-service applications

0.10.0 2017-09-20

  • Added
    • Now includes package-lock.json if it exists
    • Debian package now has a dependency on sudo which is needed for starting the app with Upstart

0.9.1 2017-09-07

  • Fixed
    • When using the intall strategy copy or auto, symlinks in node_modules are dereferenced

0.9.0 2017-04-23

  • BREAKING
    • Apps are now started with either .node_deb.entrypoints.cli or .node_deb.entrypoints.daemon and not .start or .node_deb.start_command in package.json. See README.md for more details.
  • Fixed
    • CLI apps don't cd to the install root before executing

0.8.0 2017-04-04

  • Fixed
    • Broken node_modules was fixed by the addition of --install-strategy option
  • Added
    • Parsing of node_deb.architecture field in package.json
    • --install-strategy to decide if a package should include dependencies or add them at install time

0.7.0 2017-03-15

  • Fixed
    • More minor bash errors.
  • Added
    • --output-deb-name option to change the name of the generated debian package.
    • System V support via autogenerated init scripts.

0.6.1 2017-03-05

  • Fixed
    • Miscellaneous bash errors.

0.6.0 2017-03-05

  • Changed
    • Automatically include package.json, npm-shrinkwrap.json, and node_modules. These no longer need to be specified on the command line.
    • Allow md5sums to not be calculated.
    • Deprecated the --no-md5sums CLI arg.
  • Added
    • --no-rebuild flag to prevent postinst maintainer script from running npm rebuild.
    • --arch CLI option to allow setting the architecture of the target system. Intended to be used primarily with the --no-rebuild option for finecky packages.
  • Fixed
    • node_modules is reduced down to only the production dependencies via npm ls --prod.

0.5.3 2017-03-04

  • Fixed
    • broken xargs call

0.5.2 2017-03-03

  • Fixed
    • removed lingering usage of rsync
    • fixed broken postrm script
    • made script shellcheck pure

0.5.1 2017-03-01

  • Changed
    • node-deb has reverted back to using cp instead of rsync for copying files

0.5.0 2016-12-21

  • Fixed
    • postrm now correctly cleans up /var/log/{{ package }} on purge
  • Removed
    • node-deb no longer creates /var/run/{{ package }}. This never worked correctly anyway on systems using systemd because of a typo.
  • Changed
    • postinst and prerm default to prioritizing systemctl over service and start/stop for stopping and startin services

0.4.1 2016-11-04

  • Added
    • Included LICENSE in node-deb's Debian package.
  • Changed
    • Added clarifications to README

0.4.0 2016-11-03

  • Added
    • CLI flag to display the README
    • CLI flag to display the CHANGELOG
    • More examples to the README

0.3.0 - 2016-10-30

  • Added
    • Command line flag --extra-files that adds a single directory of files to the Debian package. These files are added to the root of the file system. E.g., if the dir extra contains /var/lib/foo.dat, then the Debian package will install foo.dat to /var/lib/ at install time.

0.2.0 - 2016-09-21

  • Changed
    • Minor formatting changes, updates to README

0.1.15 - 2016-07-07

  • Added
    • Allows the default Debian dependencies in the control file to be overridden

0.1.14 - 2016-06-16

  • Added
    • The dropped commit that fixed node_modules install step mentioned in release notes from 0.1.13

0.1.13 - 2016-06-16

  • BREAKING
    • The executable template now by default includes the bash variable $@ as arguments to the start_command. This is breaking in the sense that is a user set their start_command to something like node my-exe-thing $@, then this change will pass the arguments twice.
    • The build step now forces the usage of fakeroot while creating the package to avoid uid and gid collisions between the environment where a package is built and where it is deployed.
  • Fixed
    • deb packages that did not include node_modules did not do an npm install when installed with dpkg or apt. The postinst now conditionally installs based on the existence of node_modules.
  • Added
    • Template and command line args for default environment variables. Template is empty for now.

0.1.12 - 2016-06-06

  • Fixed
    • node-deb no longer produces jq errors about missing package.json when run outside a project directory
  • Added
    • Command line option --start-command to allow setting of the start command from the command line

0.1.11 - 2016-04-21

  • BREAKING
    • Reverting the change from 0.1.9 where node-deb did not include the node_modules directory. Now the default behavior is to include this directory and warn when it is not included on the command line.
  • Added
    • Less tolerance for shell script failures both in node-deb itself and all templates
    • postinst template now runs npm rebuild to recompile platform specific binaries
      • This combined with the forced inclusion of node_modules and npm-shrinkwrap.json aims to make packages and builds as reproducible as possible.

0.1.10 - 2016-03-09

  • Changed
    • postinst now runs npm install with the --production option

0.1.9 - 2016-03-08

  • BREAKING
    • node-deb will no longer include the node_modules directory, but instead will run npm install during the postinst step in the install directory. Thus, if package.json exists, it will be auto included in the .deb.
  • Added
    • Better script logging
    • package.json and npm-shrinkwrap.json are included by default, and warning messages are displayed if they aren't included
    • If node_deb.start_command is not present in package.json, default to using scripts.start

0.1.8 - 2016-03-01

  • Changed
    • Using MIT license over GPL license
    • Slightly faster copying of files
    • Slightly faster md5sum calculations
    • Support using gmd5sum for packages built on OSX (with brew install gmd5sum)

0.1.7 - 2015-11-19

  • Changed
    • Handling of template injection that includes shell redirects

0.1.6 - 2015-10-31

  • Added
    • Command line flag --list-template-variables so users can see which variables are injected into templates
    • Allow the selections of systemd and upstart to the --init flag

0.1.5 - 2015-10-27

  • BREAKING
    • Moved installed files to /usr/share/$package_name/app/ instead of /usr/share/$package_name/ to avoid name conflicts if a user has a directory in their project called bin
  • Added
    • Command line option to list and print available templates
    • Command line options to override default templates: --template-{control, executable, postinst, postrm, prerm, systemd-service, upstart-conf}
  • Changed
    • The executable's start command now defaults to node_deb.start_command in the package.json

0.1.4 - 2015-10-26

  • Added
    • Command line flags for:
      • -d | --description: Debian package description
      • -e | --executable-name: the name of the runnable file
      • -h | --help: print help/usage message
      • -i | --init: select init type (auto, none)
      • -m | --maintainer: Debian package maintainer
      • -n | --package-name: the named of the Debian package
      • --no-md5sums: disable creating of md5sums in Debian package
    • systemd init support
    • Ability to disable init (useful for command line tools)
    • Command line options for test.sh (dev only)
  • Changed
    • Changed references from binary to executable (because that's what it actually is)
    • Command line flag -N is now named --no-delete-temp

0.1.3 - 2015-08-31

  • Added
    • Automatic removal of the .deb staging directory
    • Command line flag to prevent deletion of the .deb staging directory
    • Add md5sums for all files in the .deb directory to the DEBIAN directory in the package

0.1.2 - 2015-08-28

  • Added
    • Check to ensure all target files exist before building .deb
    • test.sh and test/ for automated testing (dev only)
  • Fixed
    • Correct handling of paths with whitespace

0.1.1 - 2015-08-26

  • Added
    • Command line flag and package.json field for Debian package version

0.1.0 - 2015-08-26

  • Added
    • Simple command line flags
    • Simple modifiers for Debian package, extracted from package.json
    • Templates for: Debian control file, preinst, postinst, prerm, binary, and Upstart script