01 简介

Review

  1. 2023-02-18 15:39

一、Introduction #

NodeJS is an open source, ==cross-platform== runtime environment and library that is used for running web applications outside the client’s browser. Node.js was written initially by Ryan Dahl in 2009.

It is used for server-side programming, and primarily deployed for non-blocking, event-driven servers, such as traditional web sites and back-end API services, but was originally designed with real-time, push-based architectures in mind. Every browser has its own version of a JS engine, and ==NodeJS is built on Google Chrome’s V8 JavaScript engine==. A NodeJS app runs in a single process, without creating a new thread for every request.1

二、源码调试 #

==for macOS==

git clone https://ghproxy.com/https://github.com/nodejs/node.git 
cd node

git checkout remotes/origin/v12.x

调试工具

  • XCode
  • VSCode
#!/usr/bin/env node

// node.js script demo
// your code

三、核心问题 #

  1. Node.js vs JavaScript
  2. 什么时候使用NodeJS
  3. EventEmitter做了什么
  4. 事件循环是什么
  5. 流是什么
  6. readFile vs createReadStream
  7. 如何处理NodeJS中未捕获的异常
  8. NodeJS能否充分利用多核处理器
  9. 反映对设计模式是什么
  10. 单线程与多线程网络后端相比有哪些好处
  11. REPL是什么
  12. process.nextTick vs setImmediate
  13. stub是什么?
  14. 为什么在express中分离“应用程序”和“服务器”是一种好的做法
  15. yarn vs npm
  16. Node.js是单线程吗?
  17. Node.js 做耗时的计算时候,如何避免阻塞?
  18. Node.js如何实现多进程的开启和关闭?
  19. Node.js可以创建线程吗?
  20. 你们开发过程中如何实现进程守护的?
  21. 除了使用第三方模块,你们自己是否封装过一个多进程架构?

View more

3.1、NodeJS vs Browser #

Both the browser and Node.js use JavaScript as their programming language. Building apps that run in the browser is entirely different than building a Node.js application. Even though it’s always JavaScript, some key differences make the experience radically different.

In the browser, most of the time what you are doing is interacting with the DOM, or other Web Platform APIs like Cookies. Those do not exist in Node.js, of course. You don’t have the documentwindow and all the other objects that are provided by the browser.

And in the browser, we don’t have all the nice APIs that Node.js provides through its modules, like the filesystem access functionality.

Another big difference is that in Node.js you control the environment. Unless you are building an open source application that anyone can deploy anywhere, you know which version of Node.js you will run the application on. Compared to the browser environment, where you don’t get the luxury to choose what browser your visitors will use, this is very convenient.

This means that you can write all the modern ES2015+ JavaScript that your Node.js version supports. Since JavaScript moves so fast, but browsers can be a bit slow to upgrade, sometimes on the web you are stuck with using older JavaScript / ECMAScript releases. You can use Babel to transform your code to be ES5-compatible before shipping it to the browser, but in Node.js, you won’t need that.

Another difference is that Node.js supports both the CommonJS and ES module systems (since Node.js v12), while in the browser we are starting to see the ES Modules standard being implemented.

In practice, this means that you can use both require() and import in Node.js, while you are limited to import in the browser.

Node.js ES Support Node Green

Reference #

  1. It’s All About NodeJS: https://dev.to/ozakaran/it-s-all-about-nodejs-37k4
  2. Keymetrics: https://keymetrics.io/
  3. Swagger – The World’s Most Popular Framework for APIs.: https://swagger.io/
  4. Passport: http://passportjs.org/
  5. Alexa: http://www.alexa.com/
  6. 玩转Nodejs日志管理log4js | 粉丝日志: http://blog.fens.me/nodejs-log4js/
  7. Practical Node.js: https://github.com/azat-co/practicalnode
  8. Now – Realtime global deployments: https://zeit.co/now
  9. Certbot: https://certbot.eff.org/#ubuntuxenial-nginx
  10. SSL Server Test: www.honeymorning.com (Powered by Qualys SSL Labs): https://www.ssllabs.com/ssltest/analyze.html?d=www.honeymorning.com
  11. 您的第一个 Progressive Web App  |  Web  |  Google Developers: https://developers.google.com/web/fundamentals/getting-started/codelabs/your-first-pwapp/?hl=zh-cn
  12. 客户端实现GitHub直接登录 · Issue #37 · TakWolf/CNode-Material-Design: https://github.com/TakWolf/CNode-Material-Design/issues/37
  13. Express 4.x API - 作业部落 Cmd Markdown 编辑阅读器: https://www.zybuluo.com/XiangZhou/note/208532
  14. 重定向 CORS 跨域请求 | Harttle Land: http://harttle.com/2016/12/30/cors-redirect.html
  15. Nodejs使用session、cookie进行登录验证功能的实现 | 但丁笔记 –一个理想主义文青的IT自留地: http://www.5941740.cn/2016/06/08/node-authority/
  16. 登录那些事儿 - CNode技术社区: https://cnodejs.org/topic/5671441a1d2912ce2a35aaa1
  17. Trello: https://trello.com/
  18. Apollo Server 1.0 — A GraphQL Server for all Node.js frameworks: https://dev-blog.apollodata.com/apollo-server-1-0-a-graphql-server-for-all-node-js-frameworks-2b37d3342f7c
  19. bcryptjs: https://www.npmjs.com/package/bcryptjs
  20. Nodemailer: https://nodemailer.com/about/
  21. Send email using nodejs and express in 5 simple steps | JavaScript: http://javascript.tutorialhorizon.com/2015/07/02/send-email-node-js-express/
  22. (99+) nodejs - Google 网上论坛: https://groups.google.com/forum/#!forum/nodejs
  23. freenode: https://freenode.net/
  24. Inspect with Chrome Developer Tools: chrome://inspect/#devices
  25. Node.js Frameworks: http://nodeframework.com/
  26. cookie 和 session - Node.js 实战心得 - 极客学院Wiki: http://wiki.jikexueyuan.com/project/node-lessons/cookie-session.html
  27. 加速electron在国内的下载速度 | Tomyail的记忆现场: http://blog.tomyail.com/install-electron-slow-in-china/
  28. How to Build and Structure a Node.js MVC Application — SitePoint: https://www.sitepoint.com/node-js-mvc-application/
  29. NodeJS 区块链: http://www.darrenbeck.co.uk/blockchain/nodejs/nodejscrypto/
  30. Express: http://expressjs.com/
  31. nodejs设置启动端口在不同系统下的写法_w3cmark: http://www.w3cmark.com/2016/436.html
  32. Node.js开发实战 https://time.geekbang.org/course/intro/100036001?tab=catalog
  33. 15 个常见的 Node.js 面试问题及答案
  34. Introduction to Node.js
  35. History of Node.js on a Timeline
  36. How Did Node.js Come About?

  1. aaa ↩︎