Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误节点不需要其定义_Javascript_Html_Node.js - Fatal编程技术网

Javascript 错误节点不需要其定义

Javascript 错误节点不需要其定义,javascript,html,node.js,Javascript,Html,Node.js,嗨,我在运行本地服务时出错了, 谢谢 server.js var https = require('https'); var fs = require('fs'); var options = { key: fs.readFileSync('privateKey.key'), cert: fs.readFileSync('certificate.crt') }; var mundo= https.createServer(options, function (req, res)

嗨,我在运行本地服务时出错了, 谢谢

server.js

var https = require('https');
var fs = require('fs');




var options = {
  key: fs.readFileSync('privateKey.key'),
  cert: fs.readFileSync('certificate.crt')
};

var mundo= https.createServer(options, function (req, res) {

  console.log(req.url)



  if(req.url === '/') {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(fs.readFileSync("./index.html"));
  }

  if(req.url === '/index.js') {
  res.writeHead(200, {'Content-Type': 'application/javascript'});
    res.end(fs.readFileSync("./index.js"));
    };


  if(req.url === '/favicon.ico') {
    res.end(fs.readFileSync("./favicon.ico"));
    };


  res.end();
  console.log("listening to port 8000");

});


mundo.listen(8443);

您正在index.js的客户端脚本中使用require。浏览器中不支持require


查看更多信息。

您好,欢迎来到Stack overflow。添加代码时请仔细查看。请添加嵌入的图像,这样回答您问题的人就不需要打开单独的窗口或走出SOF。也请尽可能具体。换句话说,请先阅读如何询问堆栈溢出问题。@DominikBucher新用户无法嵌入图像。
var getUserMedia = require('getusermedia')

getUserMedia({ video: true, audio: false }, function (err, stream) {
  if (err) return console.error(err)

  var Peer = require('simple-peer')
  console.log("conectar")
  var peer = new Peer({
    initiator: location.hash === '#init',
    trickle: false,
    stream: stream

  })

  peer.on('signal', function (data) {
    document.getElementById('yourId').value = JSON.stringify(data)
    console.log("peer on signal 1")
    console.log(data)

  })

  document.getElementById('connect').addEventListener('click', function () {
    var otherId = JSON.parse(document.getElementById('otherId').value)
    console.log("conectar")
    peer.signal(otherId)
  })

  document.getElementById('send').addEventListener('click', function () {
    var yourMessage = document.getElementById('yourMessage').value
    console.log("getElementById")
    peer.send(yourMessage)
  })

  peer.on('data', function (data) {
    console.log("peer data")
    document.getElementById('messages').textContent += data + '\n'
  })

  peer.on('stream', function (stream) {
    console.log("stream")
    var video = document.createElement('video')
    document.body.appendChild(video)

    video.src = window.URL.createObjectURL(stream)
    video.play()
  })
})
var https = require('https');
var fs = require('fs');




var options = {
  key: fs.readFileSync('privateKey.key'),
  cert: fs.readFileSync('certificate.crt')
};

var mundo= https.createServer(options, function (req, res) {

  console.log(req.url)



  if(req.url === '/') {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(fs.readFileSync("./index.html"));
  }

  if(req.url === '/index.js') {
  res.writeHead(200, {'Content-Type': 'application/javascript'});
    res.end(fs.readFileSync("./index.js"));
    };


  if(req.url === '/favicon.ico') {
    res.end(fs.readFileSync("./favicon.ico"));
    };


  res.end();
  console.log("listening to port 8000");

});


mundo.listen(8443);