How to call a node.js script in a javascript tags …











up vote
-1
down vote

favorite












I am making an api call and want to store the result into a table. Since the response i get is stored in javascript i have to use node.js for database connection (please let me know if there is a better way around). For that i have a node.js script. I want to call the node.js script in the javascript tags where i make the api call so that i can save the response in the table.



So how do I call a node.js script in a javascript?



var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "",
password: "",
database: ""
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
//Insert a record in the "customers" table:
var sql = "UPDATE portal SET similarity=$semantic WHERE id=$id[i]";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});









share|improve this question




















  • 1




    You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
    – jakerella
    Nov 19 at 18:24















up vote
-1
down vote

favorite












I am making an api call and want to store the result into a table. Since the response i get is stored in javascript i have to use node.js for database connection (please let me know if there is a better way around). For that i have a node.js script. I want to call the node.js script in the javascript tags where i make the api call so that i can save the response in the table.



So how do I call a node.js script in a javascript?



var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "",
password: "",
database: ""
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
//Insert a record in the "customers" table:
var sql = "UPDATE portal SET similarity=$semantic WHERE id=$id[i]";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});









share|improve this question




















  • 1




    You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
    – jakerella
    Nov 19 at 18:24













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am making an api call and want to store the result into a table. Since the response i get is stored in javascript i have to use node.js for database connection (please let me know if there is a better way around). For that i have a node.js script. I want to call the node.js script in the javascript tags where i make the api call so that i can save the response in the table.



So how do I call a node.js script in a javascript?



var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "",
password: "",
database: ""
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
//Insert a record in the "customers" table:
var sql = "UPDATE portal SET similarity=$semantic WHERE id=$id[i]";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});









share|improve this question















I am making an api call and want to store the result into a table. Since the response i get is stored in javascript i have to use node.js for database connection (please let me know if there is a better way around). For that i have a node.js script. I want to call the node.js script in the javascript tags where i make the api call so that i can save the response in the table.



So how do I call a node.js script in a javascript?



var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "",
password: "",
database: ""
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
//Insert a record in the "customers" table:
var sql = "UPDATE portal SET similarity=$semantic WHERE id=$id[i]";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});






javascript node.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 18:23









jakerella

9,48022546




9,48022546










asked Nov 19 at 17:25









Esha Patel

21




21








  • 1




    You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
    – jakerella
    Nov 19 at 18:24














  • 1




    You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
    – jakerella
    Nov 19 at 18:24








1




1




You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
– jakerella
Nov 19 at 18:24




You cannot directly call a Node.js script from an HTML document using a <script> tag... is that what you're trying to do? If so, you would need to use something like Express to create a back end API with an API route that would do the thing you have above.
– jakerella
Nov 19 at 18:24

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379778%2fhow-to-call-a-node-js-script-in-a-javascript-tags-script-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379778%2fhow-to-call-a-node-js-script-in-a-javascript-tags-script-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin