cancel
Showing results for 
Search instead for 
Did you mean: 

SAP HANA XS Advanced Application - Node.js service Frequently crashed

hemagopi
Explorer
0 Kudos
216

Dear @thomas_jung,

Lately, we have successfully upgraded the SAP HANA XS Advanced Application from XSJS to Node.js service. Applications are operating without issue as well. However, we have one problem. "Frequently crashing the node js service" is the problem. Could you kindly locate the code below?

Error Screen Short :- 
Node js Error.png

 

 

 

 

Server.js Code :- 

"use strict";
const https = require("https");
//Initialize Express App for XS UAA and HDBEXT Middleware
const express = require("express");
//const multer = require('multer');
 
let app = express();
app.use(express.json({
limit: '10mb',
extended: true
}));
app.use(express.urlencoded({
limit: "10mb",
extended: true,
parameterLimit: 50000
}));
const port = process.env.PORT || 3000;
const server = require("http").createServer();
 
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
 
//Initialize Express App for XSA UAA and HDBEXT Middleware
const xsenv = require("@sap/xsenv");
const passport = require("passport");
const xssec = require("@sap/xssec");
const xsHDBConn = require("@sap/hdbext");
xsenv.loadEnv();
 
https.globalAgent.options.ca = xsenv.loadCertificates();
global.__base = __dirname + "/";
global.__uaa = process.env.UAA_SERVICE_NAME;
 
//logging
let logging = require("@sap/logging");
let appContext = logging.createAppContext();
 
//Build a JWT Strategy from the bound UAA resource
passport.use("JWT", new xssec.JWTStrategy(xsenv.getServices({
uaa: {
tag: "xsuaa"
}
}).uaa));
 
//Add XS Logging to Express
app.use(logging.middleware({
appContext: appContext,
logNetwork: true
}));
 
//Add Passport JWT processing
app.use(passport.initialize());
 
let hanaOptions = xsenv.getServices({
hana: {
plan: "hdi-shared"
}
});
 
hanaOptions.hana.pooling = true;
//Add Passport for Authentication via JWT + HANA DB connection as Middleware in Expess
app.use(
xsHDBConn.middleware(hanaOptions.hana),
passport.authenticate("JWT", {
session: false
})
);
 
//Setup Additional Node.js Routes
require("./router")(app, server);
 
//Start the Server
server.on("request", app);
 
server.listen(port, function () {
console.info('HTTP Server: ${server.address().port}');
});
app.timeout = 60000;


router/ index.js :-
 
"use strict";
module.exports = (app, server) => {
app.use("/node/crm", require("./routes/crm")());
app.use((err, req, res, next) => {
console.error(JSON.stringify(err));
res.status(500).send(err);
});
};

routes/crm.js :-
 
"use strict";
var express = require("express");
 
module.exports = function () {
var app = express.Router();
app.get("/addEditEnquiry", (req, res) => {
let client = req.db;
let reqBody = req.query;
var LogNumber = reqBody.LogNumber;
var CustomerRef = reqBody.CustomerRef;
var dtEnquiryDate = reqBody.dtEnquiryDate;
var prjEndClient = reqBody.prjEndClient;
var bidtargetDate = reqBody.bidtargetDate;
var ProjectTitle = reqBody.ProjectTitle;
var sScope = reqBody.sScope;
var cmbcustomer = reqBody.cmbcustomer;
var cmbCompany = reqBody.cmbCompany;
var usercode = reqBody.usercode;
var bidtargetDateext = reqBody.bidtargetDateext;
var bidpriority = reqBody.bidpriority;
var ackwdate = reqBody.ackwdate;
var prjclass = reqBody.prjclass;
var bidtype = reqBody.bidtype;
var bidowner = reqBody.bidowner;
var days = reqBody.days;
var emailTitle = reqBody.emailTitle;
var destination = reqBody.destination;
var clientstatus = reqBody.clientstatus;
var result = '';
client.prepare(
`CALL "Fabapp.db.procedures.crm::USP_ADDEDITENQUIRY"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
(err, statement) => {
if (err) {
console.error('Prepare statement error:', err); // Log preparation errors
return res.status(500).send(`ERROR: ${err.message}`);
//return res.type("text/plain").status(500).send(`ERROR: ${err.message}`);
}
statement.exec([LogNumber, CustomerRef, dtEnquiryDate, prjEndClient, bidtargetDate, ProjectTitle, sScope, cmbcustomer, cmbCompany,
usercode, bidtargetDateext, bidpriority, ackwdate, prjclass, bidtype, bidowner, days, emailTitle, destination, clientstatus
],
(err, results) => {
if (err) {
console.error('Execution error:', err); // Log execution errors
return res.status(500).send(`ERROR: ${err.message}`);
//return res.type("text/plain").status(500).send(`ERROR: ${err.message}`);
} else {
 
if (results.length > 0) {
for (var index in results) {
result = results[index].STEXT;
}
}
return res.type("application/json").status(200).send(result);
}
});
return null;
});
return null;
});

return app;
};

package.json :-
 
{
"dependencies": {
"express": "^4.17",
"@sap/xssec": "^2.2",
"@sap/xsenv": "^2.2",
"@sap/hdbext": "~6.2",
"@sap/textbundle": "latest",
"@sap/logging": "~5.2",
"passport": "~0.4.0",
"async": "latest",
"winston": "~3.2",
"body-parser": "~1.19",
"then-request": "latest",
"nodemailer": "^6.2.1",
"request": "2.88.2"
},
"description": "my description",
"devDependencies": {
"jest": "^23.6.0",
"jest-junit": "^5.2.0"
},
"files": [],
"main": "server.js",
"name": "core_node",
"scripts": {
"test": "node node_modules/jest/bin/jest --config jest.json",
"test-coverage": "node node_modules/jest/bin/jest --coverage --config jest.json",
"start": "node server.js"
},
"engines": {
"node": "10.x"
},
"version": "1.0.0"
}
 
 
 
gregorw
Active Contributor
I would highly recommend to upgrade to a supported Node.JS version and also upgrade all NPM Packages
hemagopi
Explorer
0 Kudos

Dear Gregorw,

As per your suggestion, We are change the node version "node": "12.x". Still we are facing same issue.

9/10/24 2:50:06.642 PM [APP/53-0] ERR   
9/10/24 2:50:06.642 PM [APP/53-0] ERR   
9/10/24 2:50:06.642 PM [APP/53-0] ERR   #
9/10/24 2:50:06.642 PM [APP/53-0] ERR   # Fatal error in , line 0
9/10/24 2:50:06.642 PM [APP/53-0] ERR   # Check failed: IsEmpty().
9/10/24 2:50:06.642 PM [APP/53-0] ERR   #
9/10/24 2:50:06.642 PM [APP/53-0] ERR   #
9/10/24 2:50:06.642 PM [APP/53-0] ERR   #
9/10/24 2:50:06.642 PM [APP/53-0] ERR   #FailureMessage Object: 0x7fff94e9e070

gregorw
Active Contributor
0 Kudos
Please check https://nodejs.org/en/about/previous-releases for what is the supported version. You would need to update the buildpack on your HANA XSA of couse also.
hemagopi
Explorer
0 Kudos

Dear @gregorw,
Following a node.js version update. We are still having this problem. Would you provide any other options?

View Entire Topic
hemagopi
Explorer
0 Kudos

Thanks for reply. I will test it.