这个问题和头衔的问题非常相似,我对此绝对怀疑,这是否可能?我读到的所有关于服务器端应用程序的文章都指向了数据库,如SQL或Web以外的其他东西.

所以我想知道是否有可能简单地在一个文本区域上提交一些东西,然后存储在node.js制作的服务器应用程序上

例如:

var express = require('express');
var bodyParser = require('body-parser');
var app     = express();


//here is 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 which I would like to store what users input on my localhost -->

            <input id="submit_text_are" type="submit" value="Submit">
          
        </form>
</div>

只是一些额外的信息,我有我的根目录,名为:我的项目

里面有5个文件夹+index.html

一个文件夹名是js,它依赖于我的js程序到我的html和由node.js生成的serverSide.js.

我之所以添加这个信息,是因为我已经在这里看到了很多关于一些问题的答案,这些问题可能涉及到您的文件夹在哪里创建了您的服务器Side,其中node.js很重要.

推荐答案

可以,例如,您可以将数据存储在json文件中.你可以看到一个herehere的例子. 但对于真正的应用程序来说,这不是一个好主意.

对于你的情况来说,这样的事情应该会奏效.

const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const path = require('path');
const app = express();

// Middleware to parse JSON and urlencoded data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/saveInput', (req, res) => {
    // Get the message from the request body
    const { Nome, Questio } = req.body;
    console.log( Nome, Questio )
    // Write the message to a JSON file
    const data = JSON.stringify({  Nome, Questio }) + '\n';
    fs.appendFile(path.join(__dirname, 'message.json'), data, (err) => {
        if (err) {
            console.error('Error writing message to file:', err);
            res.status(500).send('Internal Server Error');
        } else {
            console.log('Message written to file');
            res.status(200).send('Message written to file');
        }
    });
});

// Start the server
const port = 3000;
app.listen(port, () => {
    console.log(`Server running at http://127.0.0.1:${port}/`);
});
<script>
document.getElementById('formCritic').addEventListener('submit', function(event) {
    event.preventDefault(); // Prevent the default form submission behavior

    const formData = new FormData(this);
    fetch('http://localhost:3000/saveInput', {
        method: 'POST',
        body: formData
    })
});


</script>

<div class="Contact_info">
    <h1 id="Resume">Nos aconselhe</h1><!-- Give us some advice form -->
    <form id="formCritic" action="http://localhost:3000/saveInput" method="post"> <!-- Specify the POST method and endpoint -->
        <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>
        <input id="submit_text_are" type="submit" value="Submit">
    </form>
</div>

只需确保目录中有一个文件Message.json即可.

Javascript相关问答推荐

如何修复内容安全策略指令脚本-SRC自身错误?

*ngFor和@代表输入decorator 和选角闭合

vanillajs-datepicker未设置输入值,日期单击时未触发更改事件

使用JavaScript单击上一个或下一个特定按钮创建卡滑动器以滑动单个卡

colored颜色 检测JS,平均图像 colored颜色 检测JS

给定一个凸多边形作为一组边,如何根据到最近边的距离填充里面的区域

在grafana情节,避免冲突的情节和传说

处理时间和字符串时MySQL表中显示的日期无效

对网格项目进行垂直排序不起作用

正则表达式,允许我匹配除已定义的子字符串之外的所有内容

如何在使用rhandsontable生成表时扩展数字输入验证?

如何在Svelte中从一个codec函数中调用error()?

为什么在函数中添加粒子的速率大于删除粒子的速率?

P5JS-绘制不重叠的圆

如何使用[ModelJSON,ArrayBuffer]调用tf.loadGraphModelSync

bootstrap S JS赢得了REACT中的函数/加载

需要RTK-在ReactJS中查询多个组件的Mutations 数据

是否有静态版本的`instanceof`?

我如何才能让p5.js在不使用实例模式的情况下工作?

使用JAVASCRIPT-使用If和Else If多次判断条件-使用JAVASRIPT对象及其属性