submit data to node.js server without form. no require no import , they don't work










0















I know that maybe I get some negative votes. but it is not a big problem.I have no other option.
I tried too much to send data to my node.js server without using form.
I used axios. but my main.js doesn't know axios. i installed it



 npm install axios


I imported it



 import axios from ('axios')


but I got the error ( unexpected Identifier)



after that I tried require



 var axios = require ('axios')


but I got the error ( require is not defined)



I installed browserify



 npm install broweserify


after that I bundled it with this code



browserify main.js -o bundle.js


but the same error still remains



require is not defined.



has somebody a solution.



APPRECIATED










share|improve this question






















  • How do you execute this main.js?

    – shkaper
    Nov 13 '18 at 23:10











  • This might help stackoverflow.com/questions/28696511/…

    – RedPandaz
    Nov 13 '18 at 23:16











  • @RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

    – mojtaba1
    Nov 13 '18 at 23:51











  • @shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

    – mojtaba1
    Nov 13 '18 at 23:51
















0















I know that maybe I get some negative votes. but it is not a big problem.I have no other option.
I tried too much to send data to my node.js server without using form.
I used axios. but my main.js doesn't know axios. i installed it



 npm install axios


I imported it



 import axios from ('axios')


but I got the error ( unexpected Identifier)



after that I tried require



 var axios = require ('axios')


but I got the error ( require is not defined)



I installed browserify



 npm install broweserify


after that I bundled it with this code



browserify main.js -o bundle.js


but the same error still remains



require is not defined.



has somebody a solution.



APPRECIATED










share|improve this question






















  • How do you execute this main.js?

    – shkaper
    Nov 13 '18 at 23:10











  • This might help stackoverflow.com/questions/28696511/…

    – RedPandaz
    Nov 13 '18 at 23:16











  • @RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

    – mojtaba1
    Nov 13 '18 at 23:51











  • @shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

    – mojtaba1
    Nov 13 '18 at 23:51














0












0








0








I know that maybe I get some negative votes. but it is not a big problem.I have no other option.
I tried too much to send data to my node.js server without using form.
I used axios. but my main.js doesn't know axios. i installed it



 npm install axios


I imported it



 import axios from ('axios')


but I got the error ( unexpected Identifier)



after that I tried require



 var axios = require ('axios')


but I got the error ( require is not defined)



I installed browserify



 npm install broweserify


after that I bundled it with this code



browserify main.js -o bundle.js


but the same error still remains



require is not defined.



has somebody a solution.



APPRECIATED










share|improve this question














I know that maybe I get some negative votes. but it is not a big problem.I have no other option.
I tried too much to send data to my node.js server without using form.
I used axios. but my main.js doesn't know axios. i installed it



 npm install axios


I imported it



 import axios from ('axios')


but I got the error ( unexpected Identifier)



after that I tried require



 var axios = require ('axios')


but I got the error ( require is not defined)



I installed browserify



 npm install broweserify


after that I bundled it with this code



browserify main.js -o bundle.js


but the same error still remains



require is not defined.



has somebody a solution.



APPRECIATED







javascript node.js axios browserify require






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 23:05









mojtaba1mojtaba1

95




95












  • How do you execute this main.js?

    – shkaper
    Nov 13 '18 at 23:10











  • This might help stackoverflow.com/questions/28696511/…

    – RedPandaz
    Nov 13 '18 at 23:16











  • @RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

    – mojtaba1
    Nov 13 '18 at 23:51











  • @shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

    – mojtaba1
    Nov 13 '18 at 23:51


















  • How do you execute this main.js?

    – shkaper
    Nov 13 '18 at 23:10











  • This might help stackoverflow.com/questions/28696511/…

    – RedPandaz
    Nov 13 '18 at 23:16











  • @RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

    – mojtaba1
    Nov 13 '18 at 23:51











  • @shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

    – mojtaba1
    Nov 13 '18 at 23:51

















How do you execute this main.js?

– shkaper
Nov 13 '18 at 23:10





How do you execute this main.js?

– shkaper
Nov 13 '18 at 23:10













This might help stackoverflow.com/questions/28696511/…

– RedPandaz
Nov 13 '18 at 23:16





This might help stackoverflow.com/questions/28696511/…

– RedPandaz
Nov 13 '18 at 23:16













@RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

– mojtaba1
Nov 13 '18 at 23:51





@RedPandaz thank you. that is exactly what I did. but I don't know why it doesn't work

– mojtaba1
Nov 13 '18 at 23:51













@shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

– mojtaba1
Nov 13 '18 at 23:51






@shkaper , thanks. I have many functions in my main.js . these functions are being called through index.html and other pages. one page is articles.ejs that wants to send data to server, without using forms. but until now I couldn't do it

– mojtaba1
Nov 13 '18 at 23:51













1 Answer
1






active

oldest

votes


















0














Your import syntax seems to be wrong, maybe that is the reason. You don't need the parantheses in import:



import axios from 'axios'


I'm also guessing that you are running this code in front-end and not in node.js. that's probably why you get 'require is not defined' error. (see: https://stackoverflow.com/a/9901097/7228779 )



It also looks like you misspelled browserify (not broweserify) in your install command, so that might be an issue too.






share|improve this answer























  • thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

    – mojtaba1
    Nov 14 '18 at 9:22











  • "unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

    – selmanbey
    Nov 14 '18 at 13:12











  • thanks a lot. I will learn it. appreciated

    – mojtaba1
    Nov 14 '18 at 16:24










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',
autoActivateHeartbeat: false,
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%2f53290830%2fsubmit-data-to-node-js-server-without-form-no-require-no-import-they-dont-wo%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your import syntax seems to be wrong, maybe that is the reason. You don't need the parantheses in import:



import axios from 'axios'


I'm also guessing that you are running this code in front-end and not in node.js. that's probably why you get 'require is not defined' error. (see: https://stackoverflow.com/a/9901097/7228779 )



It also looks like you misspelled browserify (not broweserify) in your install command, so that might be an issue too.






share|improve this answer























  • thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

    – mojtaba1
    Nov 14 '18 at 9:22











  • "unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

    – selmanbey
    Nov 14 '18 at 13:12











  • thanks a lot. I will learn it. appreciated

    – mojtaba1
    Nov 14 '18 at 16:24















0














Your import syntax seems to be wrong, maybe that is the reason. You don't need the parantheses in import:



import axios from 'axios'


I'm also guessing that you are running this code in front-end and not in node.js. that's probably why you get 'require is not defined' error. (see: https://stackoverflow.com/a/9901097/7228779 )



It also looks like you misspelled browserify (not broweserify) in your install command, so that might be an issue too.






share|improve this answer























  • thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

    – mojtaba1
    Nov 14 '18 at 9:22











  • "unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

    – selmanbey
    Nov 14 '18 at 13:12











  • thanks a lot. I will learn it. appreciated

    – mojtaba1
    Nov 14 '18 at 16:24













0












0








0







Your import syntax seems to be wrong, maybe that is the reason. You don't need the parantheses in import:



import axios from 'axios'


I'm also guessing that you are running this code in front-end and not in node.js. that's probably why you get 'require is not defined' error. (see: https://stackoverflow.com/a/9901097/7228779 )



It also looks like you misspelled browserify (not broweserify) in your install command, so that might be an issue too.






share|improve this answer













Your import syntax seems to be wrong, maybe that is the reason. You don't need the parantheses in import:



import axios from 'axios'


I'm also guessing that you are running this code in front-end and not in node.js. that's probably why you get 'require is not defined' error. (see: https://stackoverflow.com/a/9901097/7228779 )



It also looks like you misspelled browserify (not broweserify) in your install command, so that might be an issue too.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 0:54









selmanbeyselmanbey

537




537












  • thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

    – mojtaba1
    Nov 14 '18 at 9:22











  • "unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

    – selmanbey
    Nov 14 '18 at 13:12











  • thanks a lot. I will learn it. appreciated

    – mojtaba1
    Nov 14 '18 at 16:24

















  • thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

    – mojtaba1
    Nov 14 '18 at 9:22











  • "unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

    – selmanbey
    Nov 14 '18 at 13:12











  • thanks a lot. I will learn it. appreciated

    – mojtaba1
    Nov 14 '18 at 16:24
















thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

– mojtaba1
Nov 14 '18 at 9:22





thanks a lot. these mistakes are my misspelling just here and not in my code. ja I am using it in front-end because as I said, I want to send data to server without using form. about browserify . I have installed it successfully and I bundeled main.js with bundle.js etc.... somebody told me that I can use fetch api. do you know about it? appreciated

– mojtaba1
Nov 14 '18 at 9:22













"unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

– selmanbey
Nov 14 '18 at 13:12





"unexpected identifier" usually indicates that you have a misspelling, syntax error etc in your code. you can find it by paying attention to your error message. the message is supposed to point out where the error might be (it's not always super helpful, but it usually is). fetch() allows you to make a promise-based async requests with a clean syntax, so sure, you can use it to send data back and forth between your client and server. but I doubt it has anything to do with your question/problem. if you want to learn more about fetch, this is a good read: davidwalsh.name/fetch

– selmanbey
Nov 14 '18 at 13:12













thanks a lot. I will learn it. appreciated

– mojtaba1
Nov 14 '18 at 16:24





thanks a lot. I will learn it. appreciated

– mojtaba1
Nov 14 '18 at 16:24

















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290830%2fsubmit-data-to-node-js-server-without-form-no-require-no-import-they-dont-wo%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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto