I have setup with ASP.Net Core with Node JS service and I want to run this. Still I get the error.
var https = require('https'), // Module for https
fs = require('fs'); // Required to read certs and keys
var options = {
hostname: 'api.ssg-wsg.sg', // Production Base URL
path: '/skillsFramework/sectors', // This API is to retrieve all Sectors
method: 'GET', // Method : Get or POST
key: fs.readFileSync('C://Users/Kishan/key.pem'), //Input the directory for key.pem
cert: fs.readFileSync('C://Users/Kishan/cert.pem') //Input the directory for cert.pem
//passphrase: 'InputPassWord' //Input the passphrase, please remember to put ',' End of Line for cert
};
makeAPICall = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
});
}
https.request(options, makeAPICall).end();
you don't say how you are trying to run this script.
I assume you are trying to use Microsoft.AspNetCore.NodeServices. the issue you are having is the service runs npm, not node. npm is a package manager.
it is used to build node programs (the watcher feature typically uses express to host a running version of the program). the service is running the equivalent of:
npm run <your script name>
first get this to manually work, then use the node service. if you want npm to run your program, you first need to create a package.json
npm --init
then add your script program to the scripts section and have node run it
this is a preset round about way to start a node program. I'd probably run node directly at startup rather than using the node service. as suggested in the source, if run on windows, use cmd /c to get proper stdin/stdout redirection.
note2: back in 2.1 days, spa services ran node directly and could execute script fragments, but this feature was dropped.
you need to specify the version of .net core you are using and the code you used to create _nodeServices.
it appears you are using asp.net core 2.1 NodeServices (which is obsolete and not supported in future versions). that service requires the script be a module. simple echo module:
var https = require('https'), // Module for https fs = require('fs'); // Required to read certs and keys
var options = {
hostname: 'api.ssg-wsg.sg', // Production Base URL
path: '/skillsFramework/sectors', // This API is to retrieve all Sectors
method: 'GET', // Method : Get or POST
key: fs.readFileSync('C://Users/Kishan/key.pem'), //Input the directory for key.pem
cert: fs.readFileSync('C://Users/Kishan/cert.pem') //Input the directory for cert.pem
//passphrase: 'InputPassWord' //Input the passphrase, please remember to put ',' End of Line for cert
};
module.exports = function(callback)
{
var makeAPICall = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
callback(null, str); //send back
});
};
https.request(options, makeAPICall).end();
};
its not clear you you would not just write this in c#
None
0 Points
13 Posts
Node JS Service with ASP.Net Core
Nov 25, 2020 02:41 PM|kishanbunny|LINK
I have setup with ASP.Net Core with Node JS service and I want to run this. Still I get the error.
Please, someone help me. I really stuck in this.
Kindly,
Kishan
All-Star
57864 Points
15491 Posts
Re: Node JS Service with ASP.Net Core
Nov 25, 2020 04:34 PM|bruce (sqlwork.com)|LINK
you don't say how you are trying to run this script.
I assume you are trying to use Microsoft.AspNetCore.NodeServices. the issue you are having is the service runs npm, not node. npm is a package manager. it is used to build node programs (the watcher feature typically uses express to host a running version of the program). the service is running the equivalent of:
npm run <your script name>
first get this to manually work, then use the node service. if you want npm to run your program, you first need to create a package.json
npm --init
then add your script program to the scripts section and have node run it
"scripts": {
"prod": "node test.js"
},
then its just:
npm run prod
note: services source:
https://github.com/dotnet/aspnetcore/blob/db3d23b3af6c2ade6635faac35cbaff4a94694c1/src/Middleware/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs
this is a preset round about way to start a node program. I'd probably run node directly at startup rather than using the node service. as suggested in the source, if run on windows, use cmd /c to get proper stdin/stdout redirection.
note2: back in 2.1 days, spa services ran node directly and could execute script fragments, but this feature was dropped.
https://github.com/dotnet/aspnetcore/issues/12890
None
0 Points
13 Posts
Re: Node JS Service with ASP.Net Core
Nov 25, 2020 05:01 PM|kishanbunny|LINK
Thank you for your support. I am slowly getting it. I hope I can run my scripts.
Here, how I run the script =>
All-Star
57864 Points
15491 Posts
Re: Node JS Service with ASP.Net Core
Nov 25, 2020 07:37 PM|bruce (sqlwork.com)|LINK
you need to specify the version of .net core you are using and the code you used to create _nodeServices.
it appears you are using asp.net core 2.1 NodeServices (which is obsolete and not supported in future versions). that service requires the script be a module. simple echo module:
to convert your script:
its not clear you you would not just write this in c#