How to deploy a node.js app with maven?

Rafal Pastuszak picture Rafal Pastuszak · Jun 14, 2013 · Viewed 59.4k times · Source

Most of our team consists of java developers and therefore the whole build / deployment / dependency management system is built on top of maven. We use CI so every build process runs unit test (w. karma and phantomJS for the frontend, and jasmine-node for the backend). I've managed to configure a karma maven plugin for this purpose.

This does not solve the issue of downloading node.js dependencies from package.json on build. I need to deploy my node.js / express app in existing environment, so the perfect scenario would be:

  1. pull from the repo (done automatically with maven build)
  2. npm install (that is - downloading dependencies from node package registry)
  3. running tests

I was trying to find a nodejs package for maven, but to be honest - as a node.js developer I do not feel very confident when it comes to choosing the right tools, since I'm not able to distinguish a bad maven plugin from a decent one.

Maybe using a shell plugin and invoking npm install from the terminal is a better choice?

What's your opinion?

Answer

Christian Ulbrich picture Christian Ulbrich · Mar 26, 2015

You've got two choices:

As a hacky solution, though still feasible you could as you've mentioned yourself, use something like maven-antrun-plugin to actually execute npm with maven.

All approaches have their pros and cons, but frontend-maven-plugin seems to be the most often used approach - but it assumes that your ci server can download from the internet arbitrary packages, whereas the "hacky" solution should also work, when your ci server has no connection to the internet at all (besides proxying the central maven repo)