Nodejs blueprint for Jhipster

Ranjith Raj D
3 min readMar 23, 2022

Jhipster is an open-source application code generator that develops the modern web application with the most popular UI frameworks and the Spring-based microservice.

This code can be used as a technical reference model to bring your new application. It contains fine-grained code using industry top-notch standards. Active community contribution shows enormous effort to push code merges at a good pace.

generator-jhipster-nodejs (nhipster) is an npm package that can help us to generate nodejs based backend projects from Jhipster. Spring-based Java code is the default backend (server code) for Jhipster. You may wish to use nodejs as your backend, or maybe you want to smell the fragrance of Javascript in all your projects. Then this reading can give you some insights into the Jhipster nodejs blueprint.

npm i -g generator-jhipster-nodejs

This blueprint does not have any impact on the client (Angular, React, Vue) creation generators. This njhipster only provide nodejs code for the backend to jhipster, so rests are inherited.

Let’s see what is Blueprint and Module in the context of jhipster. That can open up a way to show how nhipster has implemented.

Jhipster Blueprint vs Module

Installed nodejs jhipster npm package can pass as a blueprint to the jhipster command.

There are many other blueprints and modules available on the Jhipster marketplace.

Generate a simple nodejs Jhipster project using the following command. Prerequisites would be Jhipster, npm and nodejs.

jhipster --blueprints nodejs

This procedure may be simple in terms of trying nhipster in docker.

Keep your downloaded sample jdl file in the current directory (jhipster-jdl.jdl) and launch jhipster from docker

Add the following line in your jdl file to skip the client app generation

application {config {
skipClient true,
}}

Code generation Command-line instructions are below

wget https://github.com/jhipster/generator-jhipster-nodejs/raw/master/docker/Dockerfiledocker build -t jhipster-generator-nodejs:latest .docker run -it --rm -v $PWD:/home/jhipster/app jhipster-generator-nodejs jhipster --blueprints nodejs jdl ./jhipster-jdl.jdl

Remove clientFramework from ./jhipster-jdl.jdl if you don’t need client code.

Explaining docker arguments, please skip if you are already familiar.

  • it: Run the docker container into interactive + pseudo terminal
  • rm: remove the container once done
  • v: Assign the current working directory as a volume to the container. So once the container is finished with the work we still have the generated files present in the host machine.
  • “jhipster-generator-nodejs” is the docker image name
  • The rest of the lines are specific to jhipster. This is an easy way to trigger a jhipster command inside the running docker through bash.
jhipster --blueprints nodejs jdl ./jhipster-jdl.jdl

Explaining jhipster arguments

  • blueprint: Providing additional generators to jhipster.
  • jdl: jhipster domain language file. It holds the information about your project metadata and entities details.
  • skip-client: Allow jhipster to generate the server-side code and skips UI code generation.

Jhipster uses the below four generators as a primary source to kick start the code generation process.

  • common
  • server
  • client
  • languages

The second layer of generators are for entities

  • entities
  • entity
  • entity-server
  • entity-client (This generator is not applicable if you use skip-client)

This blueprint has been used to extend the functionality of the above-listed generator.

Build the docker image from the generated code

docker build . -t node-app-jhipster:latest

Run your application through

docker run node-app-jhipster:latest

--

--

Ranjith Raj D

Software Architect ✦ Full stack developer ✦ Artist ✦ Autodidact ✦ Codeaholic ✦ https://www.linkedin.com/in/ranjithrajd/