How to write file inside html of server using js?










0














I want to pass data to an html and write it. I try something but it doesn't work.
I don't know how to do it what I wanted to do.



I pass this file from router to and ejs file:



router.post("/home/addfiles/rightside", function(req,res) 
var paragh = req.body.paragh ;
res.render("files/writeto",paragh:paragh);
);


Then in my ejs file I want to write the file I pass from router using js:



 <div> 
<p id="gethisformjs">

</p>
</div>

<script>
var passeddata = <%- JSON.stringify(paragh)%>
if (passeddata)
// here I want to write the above (passeddata) to <p> </p> by finding its id

</script>


I can use this:



document.getElementById("gethisformjs").innerHTML = passeddata;


But the above dose not write it permanently to the server.
I also try to use fs write method form JS but in this method I can overwrite all the file or write the file to new line, I couldn't write the file to specific location (find by id and write).



For this method I don't want to use database because I have limited space. How can I do it? any help please.










share|improve this question





















  • Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
    – James
    Nov 11 at 13:55










  • @james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
    – wzwd
    Nov 11 at 14:46










  • Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
    – ionizer
    Nov 11 at 17:45
















0














I want to pass data to an html and write it. I try something but it doesn't work.
I don't know how to do it what I wanted to do.



I pass this file from router to and ejs file:



router.post("/home/addfiles/rightside", function(req,res) 
var paragh = req.body.paragh ;
res.render("files/writeto",paragh:paragh);
);


Then in my ejs file I want to write the file I pass from router using js:



 <div> 
<p id="gethisformjs">

</p>
</div>

<script>
var passeddata = <%- JSON.stringify(paragh)%>
if (passeddata)
// here I want to write the above (passeddata) to <p> </p> by finding its id

</script>


I can use this:



document.getElementById("gethisformjs").innerHTML = passeddata;


But the above dose not write it permanently to the server.
I also try to use fs write method form JS but in this method I can overwrite all the file or write the file to new line, I couldn't write the file to specific location (find by id and write).



For this method I don't want to use database because I have limited space. How can I do it? any help please.










share|improve this question





















  • Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
    – James
    Nov 11 at 13:55










  • @james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
    – wzwd
    Nov 11 at 14:46










  • Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
    – ionizer
    Nov 11 at 17:45














0












0








0







I want to pass data to an html and write it. I try something but it doesn't work.
I don't know how to do it what I wanted to do.



I pass this file from router to and ejs file:



router.post("/home/addfiles/rightside", function(req,res) 
var paragh = req.body.paragh ;
res.render("files/writeto",paragh:paragh);
);


Then in my ejs file I want to write the file I pass from router using js:



 <div> 
<p id="gethisformjs">

</p>
</div>

<script>
var passeddata = <%- JSON.stringify(paragh)%>
if (passeddata)
// here I want to write the above (passeddata) to <p> </p> by finding its id

</script>


I can use this:



document.getElementById("gethisformjs").innerHTML = passeddata;


But the above dose not write it permanently to the server.
I also try to use fs write method form JS but in this method I can overwrite all the file or write the file to new line, I couldn't write the file to specific location (find by id and write).



For this method I don't want to use database because I have limited space. How can I do it? any help please.










share|improve this question













I want to pass data to an html and write it. I try something but it doesn't work.
I don't know how to do it what I wanted to do.



I pass this file from router to and ejs file:



router.post("/home/addfiles/rightside", function(req,res) 
var paragh = req.body.paragh ;
res.render("files/writeto",paragh:paragh);
);


Then in my ejs file I want to write the file I pass from router using js:



 <div> 
<p id="gethisformjs">

</p>
</div>

<script>
var passeddata = <%- JSON.stringify(paragh)%>
if (passeddata)
// here I want to write the above (passeddata) to <p> </p> by finding its id

</script>


I can use this:



document.getElementById("gethisformjs").innerHTML = passeddata;


But the above dose not write it permanently to the server.
I also try to use fs write method form JS but in this method I can overwrite all the file or write the file to new line, I couldn't write the file to specific location (find by id and write).



For this method I don't want to use database because I have limited space. How can I do it? any help please.







javascript node.js ejs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 13:16









wzwd

296




296











  • Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
    – James
    Nov 11 at 13:55










  • @james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
    – wzwd
    Nov 11 at 14:46










  • Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
    – ionizer
    Nov 11 at 17:45

















  • Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
    – James
    Nov 11 at 13:55










  • @james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
    – wzwd
    Nov 11 at 14:46










  • Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
    – ionizer
    Nov 11 at 17:45
















Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
– James
Nov 11 at 13:55




Your server JS and your browser JS are totally separate. Have a read through you'll need to re-think your program flow.
– James
Nov 11 at 13:55












@james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
– wzwd
Nov 11 at 14:46




@james I try many way but it doesn't do what I want. For example I put all the html cods on server JS as text then I use fs write to write them to ejs file. It do the writing but it doesn't do things that I want.
– wzwd
Nov 11 at 14:46












Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
– ionizer
Nov 11 at 17:45





Let me just give you a friendly reminder about this problem. You need the fs module on your server side. Plus on your client side script, you need to submit the data to your server, preferably by using AJAX.
– ionizer
Nov 11 at 17:45













1 Answer
1






active

oldest

votes


















1














You are trying to use the front end Js to modify files on the backend. You can not modify the file system (eg html pages or anything on the client's computer) from within the browser. To do what you are trying to do, you need to pass the data from your page to your node application and have the node application perform the modification. Performing the modification will not be easy because you will have to do a text search of the file as you do not have the DOM on the backend (you can't do document.getElementByID(... and then set innerHTML). You will have to use the fs module to access the raw text of the html.






share|improve this answer






















  • Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
    – wzwd
    Nov 11 at 18:07










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%2f53249109%2fhow-to-write-file-inside-html-of-server-using-js%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









1














You are trying to use the front end Js to modify files on the backend. You can not modify the file system (eg html pages or anything on the client's computer) from within the browser. To do what you are trying to do, you need to pass the data from your page to your node application and have the node application perform the modification. Performing the modification will not be easy because you will have to do a text search of the file as you do not have the DOM on the backend (you can't do document.getElementByID(... and then set innerHTML). You will have to use the fs module to access the raw text of the html.






share|improve this answer






















  • Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
    – wzwd
    Nov 11 at 18:07















1














You are trying to use the front end Js to modify files on the backend. You can not modify the file system (eg html pages or anything on the client's computer) from within the browser. To do what you are trying to do, you need to pass the data from your page to your node application and have the node application perform the modification. Performing the modification will not be easy because you will have to do a text search of the file as you do not have the DOM on the backend (you can't do document.getElementByID(... and then set innerHTML). You will have to use the fs module to access the raw text of the html.






share|improve this answer






















  • Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
    – wzwd
    Nov 11 at 18:07













1












1








1






You are trying to use the front end Js to modify files on the backend. You can not modify the file system (eg html pages or anything on the client's computer) from within the browser. To do what you are trying to do, you need to pass the data from your page to your node application and have the node application perform the modification. Performing the modification will not be easy because you will have to do a text search of the file as you do not have the DOM on the backend (you can't do document.getElementByID(... and then set innerHTML). You will have to use the fs module to access the raw text of the html.






share|improve this answer














You are trying to use the front end Js to modify files on the backend. You can not modify the file system (eg html pages or anything on the client's computer) from within the browser. To do what you are trying to do, you need to pass the data from your page to your node application and have the node application perform the modification. Performing the modification will not be easy because you will have to do a text search of the file as you do not have the DOM on the backend (you can't do document.getElementByID(... and then set innerHTML). You will have to use the fs module to access the raw text of the html.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 16:44

























answered Nov 11 at 16:38









Gordon A.

627




627











  • Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
    – wzwd
    Nov 11 at 18:07
















  • Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
    – wzwd
    Nov 11 at 18:07















Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
– wzwd
Nov 11 at 18:07




Thank you all. I understand that I can't do it in the way thought as in my question. But after some thinking I guess there will be another way to do it. I need to change my program flow to achieve what I plan.
– wzwd
Nov 11 at 18:07

















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%2f53249109%2fhow-to-write-file-inside-html-of-server-using-js%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo