-1
The command is running on my server machine:
$ http-server . -p 3333
Everything perfect when accessing from a web browser to another machine (also Linux).
But when running this script on Node, I cannot write to a file that is on the server, nor does it return an error. Why Fs writeFile does not work with an IP address? Is there any solution for this?
app.post('/formulario', (req, res) => {
nome = req.body.nome
idade = req.body.idade
console.log('Nome.:', nome, '\nIdade:', Number(idade)+10)
res.send('Nome.: ' + nome + '<br>Idade: ' + idade)
fs.writeFile('http://192.168.0.113:3333/arquivoTeste.txt', 'Nome.: '+ nome, function (err) {
if (err) throw err;
console.log('Escrito!');
})
res.end()
})
Thanks Gustavo. I was able to access the app from another machine through the port, etx and I realized that saved and accessed the data perfectly. It met the need. It was something simple so I did not opt for a database.
– Cicero Gomes