Write the Code. Change the World.

分类目录
7月 27

yarn run build 的时候出现 nodejs digital envelope routines::unsupported 错误。用下边处理方法:

方法一:

export NODE_OPTIONS=--openssl-legacy-provider

# 然后 再 run 就 ok 了

方法二:修改package.json,在相关构建命令之前加入set NODE_OPTIONS=--openssl-legacy-provider

"build": "set NODE_OPTIONS=--openssl-legacy-provider & webpack --config ./webpack/webpack.build.js",

6月 26

使用 ORM 可以减少数据库的操作细节,简化代码逻辑。同时,也会减少学习数据库操作更底层的东西,这个是坏事。可好事是方便,好用。

这里使用 Sequelize

https://sequelize.org/master/manual/model-basics.html

使用过任意一种语言的 ORM 的用户,这个上手起来还是蛮快的。

中文文档:
https://github.com/demopark/sequelize-docs-Zh-CN

其他
https://itbilu.com/nodejs/npm/V1Xn7hb--.html

1月 11

从零开始构建 node 项目

拥有 node,开始从零构建 node 项目吧

mkdir nodeservice

cd nodeservice

npm init

# 输入项目介绍,关键词,auth这些,一路回车,yes,成功创建 package.json 文件。
# 此时仅有该文件

然后按照需要,安装必须用到的包。少了,后边可以继续安装。

npm install express

npm install lodash

npm install moment

npm install mysql

npm install redis

npm install ioredis

npm install request

npm install socket.io

npm install socket.io-redis

npm install socketio-jwt

npm install async

npm install url

npm install jsonwebtoken

npm install bluebird

npm install china-time

npm install winston

npm install mqtt

然后创建 server.js

touch server.js

参考

https://blog.csdn.net/u013165804/article/details/80568626

https://www.jianshu.com/p/5690ebdd18fa

兜底node.js异常

unhandledRejection

12月 25

了解 model.exports export 等等

https://blog.vini123.com/187

了解各种工具包

lodash 。Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。

https://www.lodashjs.com/

moment 。 时间格式处理工具。

http://momentjs.cn/

jsonwebtoken 。用于生产及交验 token

https://github.com/auth0/node-jsonwebtoken

https://blog.csdn.net/qq_37398213/article/details/81606824

https://cloud.tencent.com/developer/article/1431793

url 。 url 模块提供了一些实用函数,用于URL处理与解析。

https://www.cnblogs.com/fengch/p/8610196.html

http://nodejs.cn/api/url.html

yeast 。根据时间戳生成唯一字符串 (做聊天的时候,生成房间 id 可以使用)

https://github.com/unshiftio/yeast

[https://blog.csdn.net/themagickeyjianan/article/details/78588257](https://blog.csdn.net/themagickeyjianan/article/details/78588257)

https://www.javascriptcn.com/read-53551.html

ioredis 。 ioredis 是一个用于 Node.js/io.js 的 Redis 客户端,强健、功能强大且全面。

https://www.oschina.net/p/ioredis
https://blog.csdn.net/qq_33589252/article/details/85535890

ws 。 ws websocket 库, node.js 的 websocket 的实现。

https://www.npmjs.com/package/ws

https://blog.csdn.net/LiMubai_CN/article/details/81844156

os 。 os 模块提供了与操作系统相关的实用方法和属性。

http://nodejs.cn/api/os.html#os_os

http://nodejs.cn/api/os/os_networkinterfaces.html

mysql 。 mysql 连接池

https://www.jianshu.com/p/2239a4df6ed5

bluebird 。bluebird 实现更强大的 Promise

https://www.ibm.com/developerworks/cn/web/wa-lo-use-bluebird-implements-power-promise/index.html

http://bluebirdjs.com/docs/getting-started.html

https://blog.csdn.net/qq_24884955/article/details/84564778

8月 29

node.js的mysql模块比较多,有mysql,mysqli,还有mariasql以及node-mariadb。针对服务器的环境,使用对应的模块。因此,踩过不少坑。

环境差异

服务器装的mysql环境,php7或php7以下

安装对应模块:

npm install mysql  // php7以下
npm install mysqli // php7

继续阅读