Home > Back-end >  Stored procedure that executes nodeJS file
Stored procedure that executes nodeJS file

Time:12-24

Everything I can find related to the title deals with having a NodeJS program that calls a stored procedure.

My question: is it possible to do the reverse? Have a stored procedure that calls/executes a NodeJS file/program? Working on a project where our database will provide some data (a few ints and a string) and then essentially send the results to a NodeJS program that enters the data into a web page form.

We are hoping to have the stored procedure provide nodeJS with the data directly as opposed to our initial thought of sending the data into a batch file that then calls nodeJS and passes in the data that way in order to reduce the steps and potential breaking points.

CodePudding user response:

Is it possible to do the reverse? Have a stored procedure that calls/executes a NodeJS file/program?

Possible, yes, but it wouldn't really "reduce the steps and potential breaking points.". You'd have to have the stored procedure launch an external process on the SQL Server that runs the nodeJS code. There's not built-in nodeJS extensibility in SQL Server like there is with .NET, Python, R, and Java, so you'd have to use xp_cmdshell, sp_start_job, SSIDB, or one of those other languages to launch the external program.

The best pattern here is to have the stored procedure write the data into some table, and have the external program consume it and do whatever. For instance you can have the NodeJS running on an application server poll for new data.

  • Related