12
I'm new to Node and Express, I was trying to make something with Express just to get started, then I faced this problem.
First res.send() works well, but the second one doesn't fire.
Here's my code:
var express = require('express'),
app = express(),
fs = require('fs'),
visits;
app.listen(8080);
app.get('/', function(req,res) {
res.send('Hello');
fs.readFile('counter.txt','utf-8', function(e,d) {
if (e) {
console.log(e);
}
else {
console.log(parseInt(d) + 1);
fs.writeFile('counter.txt',parseInt(d) + 1);
res.send('<p id="c">' + ( parseInt(d) + 1 ) + '</p>');
}
})
...
'Hello' is sent, but res.send('<p> .. </p>'); isn't. If I comment res.send('Hello');, visitors will be shown.
Thanks in advance.