Я использую Raspberry Pi 3 с Windows IoT 10. Я хочу открыть веб-страницу html в веб-браузере. Здесь raspberry pi в качестве веб-сервера должен отображать страницу html. Я пробовал в узле js, но я не могу прочитать файл html. Вот мой код
var http = require('http');
var fs = require('fs');
var path = require('path');
var filepath;
filepath = path.join(__dirname,'/assets/index.html');
console.log(filepath);
http.createServer(function (req, res) {
// console.log(filepath);
fs.readFile(filepath, function (err, data) {
if (error) return console.error("Error in finding the file");
res.writeHead(200, { 'Content-Type': 'text/html', 'Content-Length': data.length });
res.write(data);
});
}).listen(1337);
Я создал страницу index.html в папке с ресурсами. Это правильный способ разместить веб-страницу или, пожалуйста, помогите мне.
if (err) return console.error("Error in finding the file");
проверку наerr
вместоerror
- person Ezzat   schedule 19.04.2017ReferenceError: error is not defined
, как только вы попытаетесь получить этот файл - если вы не видите эту ошибку, то вы даже не обращаетесь к серверу правильно - так что... какой URL вы вводите ваш браузер? - person Jaromanda X   schedule 19.04.2017console.log(filepath)
? - person Saif Ur Rahman   schedule 29.06.2018