{"id":1344,"date":"2024-11-10T17:40:50","date_gmt":"2024-11-10T09:40:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1344\/"},"modified":"2024-11-10T17:40:50","modified_gmt":"2024-11-10T09:40:50","slug":"nodejs-%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%9c%89%e6%95%88%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95%e5%92%8c%e7%9b%91%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1344\/","title":{"rendered":"Nodejs \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173037366374071.jpg\" class=\"aligncenter\" title=\"Nodejs \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u63d2\u56fe\" alt=\"Nodejs \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u63d2\u56fe\" \/><\/p>\n<p>\u5bf9\u4e8e\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c24\u5176\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u76d1\u63a7\u548c\u65e5\u5fd7\u8bb0\u5f55\u90fd\u662f\u5173\u952e\u7ec4\u4ef6\u3002\u5b83\u4eec\u53ef\u4ee5\u6df1\u5165\u4e86\u89e3\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u72b6\u51b5\u3001\u6027\u80fd\u548c\u6f5c\u5728\u95ee\u9898\u3002\u5728 node.js \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u76d1\u63a7\u53ef\u5e2e\u52a9\u60a8\u8ddf\u8e2a\u54cd\u5e94\u65f6\u95f4\u3001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3001\u9519\u8bef\u7387\u7b49\u6307\u6807\uff0c\u540c\u65f6\u65e5\u5fd7\u8bb0\u5f55\u53ef\u6355\u83b7\u6709\u5173\u7528\u6237\u6d3b\u52a8\u3001\u9519\u8bef\u548c\u7cfb\u7edf\u6027\u80fd\u7684\u57fa\u672c\u6570\u636e\u3002\u672c\u6587\u4ecb\u7ecd\u4e86 node.js \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u6280\u672f\uff0c\u4ee5\u53ca\u5b9e\u9645\u793a\u4f8b\u548c\u4ee3\u7801\u7247\u6bb5\u3002<\/p>\n<ol>\n<li>\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u7684\u91cd\u8981\u6027<\/li>\n<li>\u5728 node.js \u4e2d\u8bbe\u7f6e\u65e5\u5fd7\u8bb0\u5f55<\/li>\n<li>\u4f7f\u7528 winston \u8fdb\u884c\u7075\u6d3b\u7684\u65e5\u5fd7\u8bb0\u5f55<\/li>\n<li>\u4f7f\u7528 prometheus \u548c grafana \u8fdb\u884c\u76d1\u63a7<\/li>\n<li>\u5b9e\u65bd\u5065\u5eb7\u68c0\u67e5<\/li>\n<li>\u5b9e\u9645\u7528\u4f8b\uff1a\u751f\u4ea7\u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7<\/li>\n<\/ol>\n<h2> \u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u7684\u91cd\u8981\u6027 <\/h2>\n<p>\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u65b9\u9762\u7684\u89c1\u89e3\uff1a<\/p>\n<ul>\n<li> <strong>\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u72b6\u51b5<\/strong>\uff1a\u6709\u5173\u9519\u8bef\u3001\u5d29\u6e83\u6216\u4e25\u91cd\u95ee\u9898\u7684\u5b9e\u65f6\u8b66\u62a5\u3002<\/li>\n<li> <strong>\u6027\u80fd\u6307\u6807<\/strong>\uff1a\u6709\u5173\u670d\u52a1\u5668\u54cd\u5e94\u65f6\u95f4\u3001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u548c\u8d1f\u8f7d\u5904\u7406\u7684\u6570\u636e\u3002<\/li>\n<li> <strong>\u7528\u6237\u6d3b\u52a8<\/strong>\uff1a\u8ddf\u8e2a\u7528\u6237\u8bf7\u6c42\u3001\u6210\u529f\u64cd\u4f5c\u548c\u9519\u8bef\u3002<\/li>\n<li> <strong>\u8c03\u8bd5<\/strong>\uff1a\u901a\u8fc7\u9519\u8bef\u65e5\u5fd7\u548c\u8ddf\u8e2a\u67e5\u660e\u95ee\u9898\uff0c\u66f4\u5feb\u5730\u8fdb\u884c\u6545\u969c\u6392\u9664\u3002<\/li>\n<\/ul>\n<h2> \u5728 node.js \u4e2d\u8bbe\u7f6e\u65e5\u5fd7\u8bb0\u5f55 <\/h2>\n<p>node.js \u6709\u4e00\u4e2a\u5185\u7f6e\u7684\u63a7\u5236\u53f0\u5bf9\u8c61\uff0c\u5b83\u63d0\u4f9b\u57fa\u672c\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\uff08console.log()\u3001console.error() \u7b49\uff09\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u53ef\u6269\u5c55\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7ed3\u6784\u5316\u4e14\u53ef\u914d\u7f6e\u7684\u65e5\u5fd7\u8bb0\u5f55\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<h4> \u57fa\u672c\u65e5\u5fd7\u8bb0\u5f55\u793a\u4f8b\uff1a <\/h4>\n<pre>\/\/ basic logging in node.js\nconsole.log(\"application started\");\nconsole.error(\"an error occurred\");\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5bf9\u4e8e\u751f\u4ea7\u7ea7\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u4f7f\u7528\u7ed3\u6784\u5316\u8bb0\u5f55\u5668\uff0c\u4f8b\u5982 <strong>winston<\/strong> \u6216 <strong>bunyan<\/strong>\u3002<\/p>\n<h2> \u4f7f\u7528 winston \u8fdb\u884c\u7075\u6d3b\u7684\u65e5\u5fd7\u8bb0\u5f55 <\/h2>\n<p><strong>winston<\/strong> \u662f node.js \u4e2d\u6d41\u884c\u7684\u65e5\u5fd7\u8bb0\u5f55\u5e93\uff0c\u5b83\u5141\u8bb8\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u7ea7\u522b\u5e76\u652f\u6301\u591a\u79cd\u4f20\u8f93\uff08\u4f8b\u5982\u6587\u4ef6\u3001\u63a7\u5236\u53f0\u3001http\uff09\u3002<\/p>\n<h3> \u8bbe\u7f6e\u6e29\u65af\u987f\uff1a <\/h3>\n<pre>const winston = require('winston');\n\nconst logger = winston.createlogger({\n    level: 'info',\n    format: winston.format.json(),\n    transports: [\n        new winston.transports.console(),\n        new winston.transports.file({ filename: 'error.log', level: 'error' }),\n        new winston.transports.file({ filename: 'combined.log' })\n    ]\n});\n\n\/\/ log messages\nlogger.info(\"this is an informational message\");\nlogger.error(\"this is an error message\");\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h2> \u4f7f\u7528 prometheus \u548c grafana \u8fdb\u884c\u76d1\u63a7 <\/h2>\n<p><strong>prometheus<\/strong> \u662f\u4e00\u4e2a\u7528\u4e8e\u6536\u96c6\u5e94\u7528\u7a0b\u5e8f\u6307\u6807\u7684\u5f3a\u5927\u5de5\u5177\uff0c<strong>grafana<\/strong> \u5141\u8bb8\u60a8\u901a\u8fc7\u8be6\u7ec6\u7684\u4eea\u8868\u677f\u53ef\u89c6\u5316\u8fd9\u4e9b\u6307\u6807\u3002<\/p>\n<h3> \u7b2c 1 \u6b65\uff1a\u5b89\u88c5 node.js \u7684 prometheus \u5ba2\u6237\u7aef <\/h3>\n<p>\u5b89\u88c5\u821e\u4f1a\u5ba2\u6237\u7aef\u5305\uff1a<\/p>\n<pre>npm install prom-client\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h3> \u7b2c 2 \u6b65\uff1a\u8bbe\u7f6e prometheus \u6307\u6807 <\/h3>\n<p>\u5728 node.js \u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u8bf7\u6c42\u6301\u7eed\u65f6\u95f4\u548c\u6d3b\u52a8\u8bf7\u6c42\u7b49\u6307\u6807\uff1a<\/p>\n<pre>const client = require('prom-client');\n\n\/\/ create metrics\nconst requestduration = new client.histogram({\n    name: 'http_request_duration_seconds',\n    help: 'duration of http requests in seconds',\n    labelnames: ['method', 'status']\n});\n\nconst activerequests = new client.gauge({\n    name: 'active_requests',\n    help: 'number of active requests'\n});\n\n\/\/ record metrics\napp.use((req, res, next) =&gt; {\n    const end = requestduration.starttimer();\n    activerequests.inc();\n\n    res.on('finish', () =&gt; {\n        end({ method: req.method, status: res.statuscode });\n        activerequests.dec();\n    });\n\n    next();\n});\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h3> \u7b2c 3 \u6b65\uff1a\u516c\u5f00\u6307\u6807\u7aef\u70b9 <\/h3>\n<p>\u521b\u5efa\u7aef\u70b9\u4ee5\u5411 prometheus \u516c\u5f00\u6307\u6807\uff1a<\/p>\n<pre>app.get('\/metrics', async (req, res) =&gt; {\n    res.set('content-type', client.register.contenttype);\n    res.send(await client.register.metrics());\n});\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h3> \u7b2c 4 \u6b65\uff1a\u4f7f\u7528 grafana \u8fdb\u884c\u53ef\u89c6\u5316 <\/h3>\n<p>\u5c06 prometheus \u8fde\u63a5\u5230 grafana \u5e76\u521b\u5efa\u81ea\u5b9a\u4e49\u4eea\u8868\u677f\u4ee5\u53ef\u89c6\u5316\u8bf7\u6c42\u7387\u3001\u5ef6\u8fdf\u548c\u5185\u5b58\u4f7f\u7528\u7b49\u6307\u6807\u3002<\/p>\n<h2> \u5b9e\u65bd\u5065\u5eb7\u68c0\u67e5 <\/h2>\n<p>\u5065\u5eb7\u68c0\u67e5\u76d1\u89c6\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u5e76\u63d0\u9192\u60a8\u53ef\u80fd\u5f71\u54cd\u53ef\u7528\u6027\u7684\u95ee\u9898\u3002\u5b83\u4eec\u53ef\u4ee5\u5305\u62ec\u5bf9\u670d\u52a1\u5668\u54cd\u5e94\u3001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u6216\u6570\u636e\u5e93\u8fde\u63a5\u7684\u57fa\u672c\u68c0\u67e5\u3002<\/p>\n<h3> \u793a\u4f8b\uff1anode.js \u4e2d\u7684\u5065\u5eb7\u68c0\u67e5\u7aef\u70b9 <\/h3>\n<pre>app.get('\/health', (req, res) =&gt; {\n    const healthstatus = {\n        uptime: process.uptime(),\n        message: 'ok',\n        timestamp: date.now()\n    };\n    res.status(200).send(healthstatus);\n});\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06\u8fd0\u884c\u72b6\u51b5\u68c0\u67e5\u4e0e <strong>aws cloudwatch<\/strong> \u6216 <strong>google cloud monitoring<\/strong> \u7b49\u76d1\u63a7\u5de5\u5177\u96c6\u6210\uff0c\u4ee5\u4fbf\u5728\u51fa\u73b0\u95ee\u9898\u65f6\u521b\u5efa\u8b66\u62a5\u3002<\/p>\n<h2> \u5b9e\u9645\u7528\u4f8b\uff1a\u751f\u4ea7\u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7 <\/h2>\n<p>\u5047\u8bbe\u60a8\u6b63\u5728 aws \u4e0a\u8fd0\u884c\u7535\u5b50\u5546\u52a1\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bcf\u79d2\u5904\u7406\u6570\u767e\u4e2a\u8bf7\u6c42\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8bbe\u7f6e\u5f3a\u5927\u7684\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\uff1a<\/p>\n<h3> \u7b2c 1 \u6b65\uff1a\u4f7f\u7528 winston \u5b9e\u65bd\u65e5\u5fd7\u8bb0\u5f55 <\/h3>\n<p>\u4f7f\u7528 <strong>winston<\/strong> \u8bb0\u5f55\u6240\u6709\u5173\u952e\u64cd\u4f5c\uff0c\u5305\u62ec\u7528\u6237\u8bf7\u6c42\u3001\u6210\u529f\u7684\u4ea4\u6613\u548c\u9519\u8bef\u3002<\/p>\n<pre>logger.info(\"User login successful\", { userId: \"12345\", timestamp: new Date() });\nlogger.error(\"Payment processing failed\", { error: error.message, timestamp: new Date() });\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h3> \u7b2c 2 \u6b65\uff1a\u8bbe\u7f6e prometheus \u8fdb\u884c\u6307\u6807\u6536\u96c6 <\/h3>\n<p>\u4f7f\u7528 <strong>prometheus<\/strong> \u8ddf\u8e2a\u8bf7\u6c42\u6301\u7eed\u65f6\u95f4\u3001\u6d3b\u52a8\u8bf7\u6c42\u548c\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7b49\u6307\u6807\u3002\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u9ad8\u6d41\u91cf\u671f\u95f4\u7684\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<h3> \u7b2c3\u6b65\uff1a\u521b\u5efa\u7528\u4e8e\u76d1\u63a7\u7684grafana\u4eea\u8868\u677f <\/h3>\n<p>\u5c06 prometheus \u6570\u636e\u8fde\u63a5\u5230 <strong>grafana<\/strong> \u5e76\u8bbe\u7f6e\u4eea\u8868\u677f\u6765\u5b9e\u65f6\u76d1\u63a7\u54cd\u5e94\u65f6\u95f4\u3001cpu \u4f7f\u7528\u7387\u548c\u9519\u8bef\u7387\u3002\u914d\u7f6e\u8b66\u62a5\u4ee5\u63a5\u6536\u4efb\u4f55\u5f02\u5e38\u60c5\u51b5\u7684\u901a\u77e5\uff0c\u4f8b\u5982\u9519\u8bef\u7387\u6fc0\u589e\u6216\u5185\u5b58\u4f7f\u7528\u7387\u8fc7\u9ad8\u3002<\/p>\n<h2> \u7ed3\u8bba <\/h2>\n<p>\u6709\u6548\u7684\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u5bf9\u4e8e\u7ba1\u7406\u548c\u6269\u5c55 node.js \u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\uff0c\u5c24\u5176\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u3002 winston \u7b49\u65e5\u5fd7\u6846\u67b6\u5141\u8bb8\u60a8\u6355\u83b7\u7ed3\u6784\u5316\u65e5\u5fd7\uff0c\u800c prometheus \u548c grafana \u7b49\u76d1\u63a7\u5de5\u5177\u53ef\u63d0\u4f9b\u6027\u80fd\u6307\u6807\u7684\u53ef\u89c1\u6027\u5e76\u5e2e\u52a9\u60a8\u66f4\u5feb\u5730\u89e3\u51b3\u95ee\u9898\u3002\u901a\u8fc7\u5b9e\u65bd\u8fd9\u4e9b\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd node.js \u5e94\u7528\u7a0b\u5e8f\u5e73\u7a33\u8fd0\u884c\u3001\u9ad8\u6548\u5904\u7406\u6d41\u91cf\u5e76\u4e3a\u7528\u6237\u63d0\u4f9b\u53ef\u9760\u7684\u4f53\u9a8c\u3002<\/p>\n<p>\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u4fdd\u62a4 node.js \u5e94\u7528\u7a0b\u5e8f\uff0c\u8ba8\u8bba https\u3001cors\u3001\u6570\u636e\u52a0\u5bc6\u7b49\u6280\u672f\u3002\u8bf7\u7ee7\u7eed\u5173\u6ce8\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNodejs \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c24\u5176\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u76d1\u63a7\u548c\u65e5\u5fd7\u8bb0\u5f55\u90fd\u662f\u5173\u952e\u7ec4\u4ef6\u3002\u5b83\u4eec\u53ef\u4ee5\u6df1\u5165\u4e86\u89e3\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u72b6\u51b5\u3001\u6027\u80fd\u548c\u6f5c\u5728\u95ee\u9898\u3002\u5728 node.js \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u76d1\u63a7\u53ef\u5e2e\u52a9\u60a8\u8ddf\u8e2a\u54cd\u5e94\u65f6\u95f4\u3001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3001\u9519\u8bef\u7387\u7b49\u6307\u6807\uff0c\u540c\u65f6\u65e5\u5fd7\u8bb0\u5f55\u53ef\u6355\u83b7\u6709\u5173\u7528\u6237\u6d3b\u52a8\u3001\u9519\u8bef\u548c\u7cfb\u7edf\u6027\u80fd\u7684\u57fa\u672c\u6570\u636e\u3002\u672c\u6587\u4ecb\u7ecd\u4e86 node.js \u5e94\u7528\u7a0b\u5e8f\u7684\u6709\u6548\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u6280\u672f\uff0c\u4ee5\u53ca\u5b9e\u9645\u793a\u4f8b\u548c\u4ee3\u7801\u7247\u6bb5\u3002 \u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u7684\u91cd\u8981\u6027 \u5728 node.js \u4e2d\u8bbe\u7f6e\u65e5\u5fd7\u8bb0\u5f55 \u4f7f\u7528 winston \u8fdb\u884c\u7075\u6d3b\u7684\u65e5\u5fd7\u8bb0\u5f55 \u4f7f\u7528 prometheus \u548c grafana \u8fdb\u884c\u76d1\u63a7 \u5b9e\u65bd\u5065\u5eb7\u68c0\u67e5 \u5b9e\u9645\u7528\u4f8b\uff1a\u751f\u4ea7\u4e2d\u7684\u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7 \u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u7684\u91cd\u8981\u6027 \u65e5\u5fd7\u8bb0\u5f55\u548c\u76d1\u63a7\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u65b9\u9762\u7684\u89c1\u89e3\uff1a \u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u72b6\u51b5\uff1a\u6709\u5173\u9519\u8bef\u3001\u5d29\u6e83\u6216\u4e25\u91cd\u95ee\u9898\u7684\u5b9e\u65f6\u8b66\u62a5\u3002 \u6027\u80fd\u6307\u6807\uff1a\u6709\u5173\u670d\u52a1\u5668\u54cd\u5e94\u65f6\u95f4\u3001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u548c\u8d1f\u8f7d\u5904\u7406\u7684\u6570\u636e\u3002 \u7528\u6237\u6d3b\u52a8\uff1a\u8ddf\u8e2a\u7528\u6237\u8bf7\u6c42\u3001\u6210\u529f\u64cd\u4f5c\u548c\u9519\u8bef\u3002 \u8c03\u8bd5\uff1a\u901a\u8fc7\u9519\u8bef\u65e5\u5fd7\u548c\u8ddf\u8e2a\u67e5\u660e\u95ee\u9898\uff0c\u66f4\u5feb\u5730\u8fdb\u884c\u6545\u969c\u6392\u9664\u3002 \u5728 node.js \u4e2d\u8bbe\u7f6e\u65e5\u5fd7\u8bb0\u5f55 node.js \u6709\u4e00\u4e2a\u5185\u7f6e\u7684\u63a7\u5236\u53f0\u5bf9\u8c61\uff0c\u5b83\u63d0\u4f9b\u57fa\u672c\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\uff08console.log()\u3001console.error() \u7b49\uff09\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u53ef\u6269\u5c55\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7ed3\u6784\u5316\u4e14\u53ef\u914d\u7f6e\u7684\u65e5\u5fd7\u8bb0\u5f55\u81f3\u5173\u91cd\u8981\u3002 \u57fa\u672c\u65e5\u5fd7\u8bb0\u5f55\u793a\u4f8b\uff1a \/\/ basic logging in node.js console.log(&#8220;application started&#8221;); console.error(&#8220;an error occurred&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u4e8e\u751f\u4ea7\u7ea7\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u4f7f\u7528\u7ed3\u6784\u5316\u8bb0\u5f55\u5668\uff0c\u4f8b\u5982 winston \u6216 bunyan\u3002 \u4f7f\u7528 winston \u8fdb\u884c\u7075\u6d3b\u7684\u65e5\u5fd7\u8bb0\u5f55 winston \u662f node.js \u4e2d\u6d41\u884c\u7684\u65e5\u5fd7\u8bb0\u5f55\u5e93\uff0c\u5b83\u5141\u8bb8\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u7ea7\u522b\u5e76\u652f\u6301\u591a\u79cd\u4f20\u8f93\uff08\u4f8b\u5982\u6587\u4ef6\u3001\u63a7\u5236\u53f0\u3001http\uff09\u3002 \u8bbe\u7f6e\u6e29\u65af\u987f\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1344","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1344"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1344\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}