V
V
Vyacheslav Lebedev2015-04-14 17:27:15
HTML
Vyacheslav Lebedev, 2015-04-14 17:27:15

Why in node, when returning html, errors pop up in the console?

096344ef758a4cb79a908c3deb669829.png
The page opens correctly.

app.get('/', function (req, res) {
    res.sendFile(__dirname + '/index.html');
});

Before that, I required the html component, installed it (but I don’t understand why, because html doesn’t need to be rendered?), now this error.
What to do?
ps: Actually this is the whole code :)
"express": "latest"
var express = require('express'),
    app = express(),
    fs = require('fs');

app.use(express.static(__dirname + '/public'));

app.get('/', function (req, res) {
    //res.sendFile(__dirname + '/index.html');
    fs.readFile(__dirname + 'index.html', 'utf8', function(err, text) {
        res.send(text);
    });
});

app.listen(8200, function () {
    console.log('Listen 8200 port');
});

UPD: Found a bug! I used to render jade and used:
app.get('*', function (req, res) {
    res.render(__dirname + '/index.html');
});

Now I switched to html, but this line remained. So she spit out errors in the console.
My carelessness.
Thanks to all! :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ILE, 2015-04-14
@slavikse

The error is because you wrote sendFIle and not sendfile f with a small letter))
so the error pops up unknown is not a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question