【发布时间】:2021-12-02 01:24:50
【问题描述】:
我在学校的 Chromebook 上,开发者工具被禁用。我有时在 node.js 上编码,有服务器端和客户端代码。但是,由于开发人员工具被禁用,我无法在客户端检查错误,只发现它有时只是停止工作而没有任何错误线索。在编写客户端代码时,我经常遇到这个问题。
我如何仅通过可视化访问 node.js 控制台以及 express 和 socket.io 来检测和识别错误?
例如,
const express=require("express");
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
app.use(
'/client',
express.static(__dirname + '/client')
);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/client/index.html');
console.log("sending site");
});
http.listen(3000, () => {
console.log('listening on *:3000 (http.listen)');
});
io.on('connection', (socket) => {
socket.emit("ERRORNOW",26);
});
//"<script src="/socket.io/socket.io.js"></script>" assumed to be in HTML file
var socket=io();
socket.on("ERRORNOW",()=>{
if("this doesnt have an ending curlybracket){
//}
//this is the error it doesnt have the ending curly bracket,
//but it doesn't show in the node.js console
//(at least on browser IDEs like repl.it),
//and debugging without the developer tools
//can be infuriating to say the least
});
问题是如何在没有开发人员工具的情况下在基于 Web 的 IDE 上识别 node.js 客户端错误?
【问题讨论】:
标签: javascript node.js express try-catch error-checking