The question is very much the same as it is on title, my aboslute doubt about it, is if this is possible ? all i’ve read about server side aplication lead to a DB like SQL or something aside from web.
So i would like to know if is it possible to simple submit something on a textarea and store on a server aplication made by node.js
for example:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
//here where i got with some help of others questions on stackoverflow
app.use(bodyParser.json());
//Note that in version 4 of express, express.bodyParser() was
//deprecated in favor of a separate 'body-parser' module.
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, function() {
console.log('Server running at http://127.0.0.1:3000/');
})
<div class="Contact_info">
<h1 id="Resume">Nos aconselhe</h1><!-- Give us some advice form -->
<form id="formCritic" action="http://localhost:3000" method="get"> <!-- this is my localhost created using JS on node.js -->
<input type="text" id="Name" name="Nome" placeholder="Seu nome.." >
<textarea class="text_area_submit" id="Questio" name="Questio" placeholder="Nos informe qualquer duvida ou problema.." ></textarea>
<!-- here is the text area wich i would like to store what users input on my localhost -->
<input id="submit_text_are" type="submit" value="Submit">
</form>
</div>
Just some extra info, i have my root directory, named : Myproject
inside it there are 5 folders + Index.html
one folder name is JS, wich relie my js program to my html and my serverSide.js made by node.js .
Im add this information, because i’ve arealdy see alot of answers on some questions here that might treat this matter about where your folder wich you’ve created your serverSide with node.js important.
2
Answers
Yes. But you’re probably misunderstanding a few things.
You can store data "in the application" in the form of just saving it to a variable in a more global scope, for example. But that data will be very short-lived. It’s not persisted anywhere, so as soon as anything happens to the running application that data will be gone.
You can also write your data to HTML files. Though as a data storage format HTML is very loosely structured and this is going to very quickly become difficult to manage.
You could store your data in any format you like though. So perhaps serializing to a JSON file would make more sense. It’s persisted outside of the application, so it’ll survive a reboot. It’s in a structured format. That could work for you.
Though as that data scales to any significant amount, or as the need to read and write the data reaches any higher volumes than just you alone, writing it to the file system becomes less performant and more cumbersome.
The solution to that is to use a database.
Yes, you can store data in json file, for example. You can see an example here or here.
But it’s not a great idea for a real application.
For your case something like this should work.
Just make sure you have a file message.json in the directory.