![](https://img-blog.csdnimg.cn/20200705201746838.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Node.js
node专题
愚公搬代码
《头衔》:华为云特约编辑,华为云云享专家,华为开发者专家,华为产品云测专家,CSDN博客专家,CSDN商业化专家,阿里云专家博主,阿里云签约作者,腾讯云优秀博主,腾讯云内容共创官,掘金优秀博主,亚马逊技领云博主,51CTO博客专家等。
《近期荣誉》:2022年度博客之星TOP2,2023年度博客之星TOP2,2022年华为云十佳博主,2023年华为云十佳博主等。
《博客内容》:.NET、Java、Python、Go、Node、前端、IOS、Android、鸿蒙、Linux、物联网、网络安全、大数据、人工智能、U3D游戏、小程序等相关领域知识。
展开
-
(精华)2020年7月10日 Node.js express(router路由的使用)
可挂载路由var express = require('express');var router = express.Router(); //可挂载路由处理程序// 路由器的中间件router.use(function timeLog (req, res, next) { console.log('Time: ', Date.now()) next()})// 首页路由router.get('/home', function (req, res) { res.json({原创 2020-07-10 06:55:24 · 559735 阅读 · 1 评论 -
(精华)2020年7月8日 Node.js mysql的使用
MYSQL数据库命令操作之前应连接某个数据库1、建表命令:create table <表名> ( <字段名> <类型> [,…<字段名n> <类型n>]);mysql> create table MyClass(> id int(4) not null primary key auto_increment,> username char(20) not null,> score char(50) not nul原创 2020-07-08 21:42:24 · 561236 阅读 · 1 评论 -
(精华)2020年7月8日 Node.js express(JWT使用)
// nodejs+express+jwt-simplelet jwt = require('jwt-simple');//秘钥let secret = "laney";let time = 10;let tokenExpiresTime = 1000 * 60 * 60 * 24 * 7; //token过期时间,毫秒为单位, 7天module.exports = { /* *检验token合法性 */ validate: function (req, res, next原创 2020-07-08 21:29:37 · 561215 阅读 · 0 评论 -
(精华)2020年7月8日 Node.js express(跨域处理)
var mysql = require('mysql'); const express = require('express');var bodyParser = require('body-parser'); //body解析var cors = require('cors'); const app = express();app.use(bodyParser.json()).use(bodyParser.urlencoded({ extended: true })).use(fun原创 2020-07-08 21:27:19 · 561193 阅读 · 0 评论 -
(精华)2020年7月8日 Node.js connect的使用文件上传
客户端<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title&g原创 2020-07-08 21:00:56 · 560727 阅读 · 0 评论 -
(精华)2020年7月8日 Node.js ws和websocket.io的使用
WS客户端1<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <titl原创 2020-07-08 20:49:39 · 561621 阅读 · 0 评论 -
(精华)2020年7月7日 Node.js http,https,tcp服务的创建
HTTP协议const http = require('http');const fs = require('fs');//request//response// eventEmitter// 响应简单请求// get/post/head,没有自定义请求头,// Content-Type是// application/x-www-form-urlencoded,// multipart/form-data或text/plain之一,// 跨域:通过添加以下响应头解决: // r原创 2020-07-08 00:01:31 · 560821 阅读 · 1 评论 -
(精华)2020年7月6日 Node.js express(手写版)
//myexpress.jsconst http = require('http');const url = require('url');let routers = [];class Application { get(path, hander) { routers.push({ path, method: 'get', hander }); } listen2() {原创 2020-07-06 21:54:37 · 563093 阅读 · 1 评论 -
(精华)2020年7月8日 Node.js 文件读取和写入
const fs = require('fs');//同步读取const data = fs.readFileSync('./package.json');console.log('data', data);console.log('data2', data.toString());//异步读取const data2 = fs.readFile('./package.json', function (err, data) { console.log('异步data', data);原创 2020-07-06 21:46:24 · 563502 阅读 · 1 评论 -
(精华)2020年7月6日 Node.js http的使用
const http = require('http');const fs = require('fs');http.createServer(function(request,response){ const {url,method,headers} = request; if(url=='/' && method=='GET'){ fs.readFile('index.html', (err, data) => {原创 2020-07-06 21:50:58 · 563500 阅读 · 1 评论 -
(精华)2020年7月6日 Node.js Buffer缓冲的使用
const buf01 = Buffer.alloc(10);console.log(buf01.toString())const buf02 = Buffer.from([10,20,30]);console.log(buf02.toString())const buf03 = Buffer.from('创建方法');buf03.write('hellouuuuuuu');console.log(buf03.toString()) //从缓冲区读取数据var mn = Buffer.原创 2020-07-06 21:49:19 · 563321 阅读 · 0 评论 -
(精华)2020年7月5日 Node.js require和module
require和module属于commonJS规范//showFun.js代码const os = require('os');module.exports = { showMem(){ const mem = os.freemem() / os.totalmem() * 100; console.log(`内存占用率${mem.toFixed(2)}`); }, showCpu(){ const cpuStat原创 2020-07-05 20:23:51 · 563838 阅读 · 1 评论