Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a node.js app with maven?

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?

like image 293
Rafal Pastuszak Avatar asked Jun 14 '13 07:06

Rafal Pastuszak


People also ask

Can we use maven for Nodejs?

Luckily, all the popular tools were developed around a single technology, Node. js, which made it easier to integrate with other technologies, such as Maven. In this article, we will use a Maven plugin, called Frontend Maven Plugin, to integrate Gulp tasks into Maven's generate-resources phase.

What is maven in node JS?

The frontend-maven-plugin defines goals for specific tools like grunt, gulp, karma, whereas the nodejs-maven-plugin has just one generic run goals that lets you execute any Node. js-based tool.

Can you use maven with javascript?

Since javascript source files are not supported in maven in the first place we have to add the new javascript source folders as a maven resource: ... src/main/javascript true ... Since the javascript folder is now a declared resource location, the content is automatically copied to the generated maven artefact.


1 Answers

You've got two choices:

  • https://github.com/eirslett/frontend-maven-plugin to let maven download your npm modules from your package.json and let it automagically install node and npm all along

  • https://github.com/mulesoft/npm-maven-plugin to let maven download your npm packages that you have specified in the pom.xml (link dead as of April 2020, seems to be discontinued)

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)

like image 60
Christian Ulbrich Avatar answered Sep 22 '22 13:09

Christian Ulbrich