To Register A NodeJs Application On Eureka Server
Posted By : Gursahib Singh | 29-Apr-2018
In this blog, we will see how to register a NodeJs application as a eureka-client on the Eureka server.
To make a nodejs application as a eureka-client we first need to install the eureka-js client using npm . The command for the installation of the same in ubuntu is "npm install eureka-js-client --save"
The next step is to make any sample.js file in the nodejs project folder. In this file, we will first add the details of the NodeJs application in the object of the Eureka client.
'use strict';
const Eureka = require('eureka-js-client').Eureka;
const client = new Eureka({
instance: {
app: 'jqservice',
hostName: 'localhost',
ipAddr: '127.0.0.1',
port: {
'$': 3000,
'@enabled': 'true',
},
vipAddress: 'jq.test.something.com',
statusPageUrl: 'http://localhost:3000/api/login',
dataCenterInfo: {
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
})
After that, we will specify the details i.e port of the Eureka server in the client object which we earlier made.
eureka: {
// eureka server host / port
host: '127.0.0.1',
port: 8090,
servicePath: '/eureka/apps/'
}
To register the application on the Eureka server, we need to invoke the client object which is done by the following code:
function connectToEureka() {
client.logger.level('debug');
client.start(function(error) {
console.log(JSON.stringify(error) || 'Eureka registration complete'); }); }
connectToEureka();
In this case, I have made a spring boot application as a Eureka server. To register an application as Eureka Server, please follow the following blogs:
1. https://my.oodles.io/blogs/To%20Setup%20Eureka%20Server%20And%20Register%20A%20Microservice.
2. https://my.oodles.io/blogs/Registering%20A%20Spring%20Boot%20Microservice%20On%20Eureka%20Server.
After saving all these changes run the Eureka Server application.
After successfully saving the sample.js file in the nodejs project folder run the following command in the node.js command prompt.
"node sample.js"
This will register the NodeJs application as a Eureka Client on the Eureka server.
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Gursahib Singh
Gursahib is a software developer having key skills in J2SE and J2EE. His hobbies are playing chess, reading and learning new softwares.