簡體   English   中英

打字稿 MQTT 代理

[英]Typescript MQTT Broker

我想在帶有角度的 Typescript 中構建一個 MQTT Broker。 我試過一些例子,但總是得到錯誤:

Uncaught TypeError: http.createServer is not a function

這是我目前正在嘗試運行的簡單示例:

var http = require('http');
var port2 = 9000;

http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello there, world\n');
}).listen(port2);

console.log("Listening on port " + port2);

有沒有人知道我從哪里得到這個錯誤,或者我可以嘗試的其他示例經紀人?

感謝您的幫助!

在使用 Node.js API 時,您的代碼可能正在瀏覽器中運行。

節點錯誤如下所示: 節點錯誤

雖然瀏覽器錯誤看起來與您在問題中提到的更相似。 瀏覽器錯誤

我為這兩個測試運行的代碼片段如下:

var http = {};
var port2 = 9000;

http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello there, world\n');
}).listen(port2);

console.log("Listening on port " + port2);

您提供的代碼段在使用 node.js 的最新 Nodejs docker 映像上運行時可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM