M
M
Maxim Nine2017-08-20 19:07:49
JavaScript
Maxim Nine, 2017-08-20 19:07:49

[fs - express.js] What's the problem?

There are always problems reading FS files.
Here is the code:

fs.readFile('/../../../../../root/projects/kulonful.ru/hiden/index.html',  function(data) {
            console.log(data);
            res.setHeader('Content-Type', 'text/html; charset=utf-8');
            res.setHeader('Dev-Help', 'https://vk.com/kulonful');
            res.end(data);
}

Gives null in the log. The result is a blank page

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abcdefgk, 2017-08-20
@Abcdefgk

Well, that's right, null means that there was no error while reading. Is it bad? If we assign one more argument to the callback function, then it will contain the successfully read file.

C
Coder321, 2017-08-20
@Coder321

The first argument in the callback is an error, the read file is the second

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question