学习路径
持续学习文档。Node.js 的文档很好,建议继续深入研究 API 和模块,了解更多的工具。
掌握模块化设计。模块化是Node.js的重要概念之一,建议学习实践更多的模块化设计模式,例如 CommonJS, AMD 和 ES6 Modules。
熟练掌握异步编程。Node.js 是异步的,异步编程将是你工作的重要方面。学习 Promise,async/await, callback等技术,掌握原理。
实践开发更多的项目。尝试开发更复杂的应用,例如实时数据传输应用,RESTful API,微服务和WebSocket等。不断地钻研项目中遇到的挑战和解决方案。
学习更多的框架和工具。了解其他一些框架和工具,例如 Koa、Nest.js、Express.js、Hapi等,也可以关注一些流行的Node.js应用部署工具,例如PM2、Docker等。
参与社区。Node.js 社区非常强大,你可以参与多个社区,例如Github、Stack Overflow、Node.js 论坛,分享自己的问题和经验,向社区高手学习。
目前已完成
- 语言基础 和 js相同 完成
- 语言特性 基本了解完成
- web框架- Express 基本了解 - 实践项目 - 本地图书馆
正在进行
- 学习KOA
- RestAPI、JXcore打包,集成数据库MySQL和Mongo。
后续阶段
多线程
资源
node应用的组成
- 引入required模块:使用require指令来载入Node.js 模块。
- 创建服务器:服务器可以监听客户端的请求,类似于HTTP服务器。
- 接受请求与响应
NPM 包管理工具
nodejs 包下载命令 npm install
express - Node.js 的web框架
REPL(交互式解释器)
类似Windows系统的终端shell,可以接受命令,并响应。
可执行任务:
- 读取
- 执行
- 打印
- 循环
事件循环
所有异步I/O操作完成时,都会发送一个事件到事件队列。
所有事件的对象都是EventEmitter的实例。
EventEmitter 提供了多个属性,on 来绑定事件函数,emit用于触发一个事件。
Buffer
JS没有二进制数据类型,node中定义了Buffer类,用来存放二进制数据的缓存区。可以用来处理TCP流和文件流。
Stream
模块系统
全局对象
__filename
__dirname
setTimeout(cb, ms); 多少毫秒之后执行函数
clearTimeout(t) t是定时器, 用于停止定时器
setInterval(cb, ms) 指定毫秒之后执行指定函数,会不断的执行,知道clearInterval()调用,或者窗口关闭。
常用工具
util是Node.js常用工具,用于弥补js的功能不足。
https://www.runoob.com/nodejs/nodejs-util.html
文件系统
node文件系统模块中的方法都有异步和同步版本。类似UNIX标准的文件操作API。
工具模块
- OS模块 操作系统函数
- Path模块 处理和转换文件路径的工具
- Net模块 底层的网络通信
- DNS模块 用于解析域名
- Domain 模块 简化异步代码的异常处理, 捕捉处理try catch无法捕捉的异常。
WEB 模块
web服务器基本功能提供web信息浏览服务。 Node 提供了http模块,用于搭建HTTP服务器和客户端。
用来编写服务器和客户端请求。
Express 框架
强大的特性创建各种web应用,丰富的HTTP工具。使用Express可以快速地搭建一个完整功能的网站。
核心:
- 可以设置中间件来响应HTTP请求。
- 定义了路由表用于执行不同的http请求。
- 可以通过模板传递参数来动态渲染HTML页面。
更多使用细节:
https://www.runoob.com/nodejs/nodejs-express-framework.html
https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/Introduction
总结
在学习了JS基本语法之后,学习Node.js比较丝滑,看完了菜鸟教程的基础教学,蠢蠢欲动,实战一下。感谢菜鸟教程。
Node应用场景:
Node.js is a popular, open-source JavaScript runtime environment that allows developers to build server-side applications using JavaScript. With Node.js, you can:
Build web servers: You can build fast and scalable web servers using Node.js and its built-in modules, such as HTTP, to handle HTTP requests and responses.
Create real-time applications: Node.js is well-suited for building real-time applications, such as chat applications and online games, due to its fast, non-blocking I/O and event-driven architecture.
Build command-line tools: Node.js can be used to build command-line tools that automate tasks and perform various operations.
Build RESTful APIs: You can use Node.js to build RESTful APIs for your web applications. You can use frameworks like Express.js to simplify the process of building APIs.
Create desktop applications: You can use Node.js and desktop application frameworks like Electron to build cross-platform desktop applications.
Automate tasks: Node.js can be used to automate various tasks, such as processing files, generating reports, and performing backups.
Build IoT applications: Node.js can be used to build Internet of Things (IoT) applications by connecting to sensors and devices and processing the data they generate.
These are just a few examples of what you can do with Node.js. The versatility and popularity of the platform have led to a rich ecosystem of libraries and tools, making it possible to build a wide variety of applications.
- Post title:Node.Js入门到实战
- Post author:郭旭升
- Create time:2023-02-08 18:11:33
- Post link:2023/02/08/nodeJs入门/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.