当前位置: 首页 > news >正文

【Node.js】官网学习笔记

Node.js 官网学习笔记

node 是什么?

  • 开源跨平台的js运行环境

  • 基于Chrome 的 V8 Js 引擎,性能强

  • asynchronous I/O + non-blocking ; 支持异步非阻塞IO

  • low-level platform,在此平台上建立了很多框架

    • Meteor: An incredibly powerful full-stack framework, powering you with an isomorphic approach to building apps with JavaScript, sharing code on the client and the server. Once an off-the-shelf tool that provided everything, now integrates with frontend libs React, Vue, and Angular. Can be used to create mobile apps as well.

node 怎么用?

Hellow Word

文件命名为server.js,并填充脚本:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

teminal里面执行

node server.js 

node 在多版本中进行控制

nvm

https://github.com/nvm-sh/nvm

怎么用好node?

I would recommend you to have a good grasp of the main JavaScript concepts before diving into Node.js:

官网强调,要深入到node.js中,最好熟悉JS的以下特性

JS特性

  • Lexical Structure
  • Expressions
  • Types
  • Classes
  • Variables
  • Functions
  • this
  • Arrow Functions
  • Loops
  • Scopes
  • Arrays
  • Template Literals
  • Semicolons
  • Strict Mode
  • ECMAScript 6, 2016, 2017

异步编程

  • Asynchronous programming and callbacks
  • Timers
  • Promises
  • Async and Await
  • Closures
  • The Event Loop

node 对js的兼容性考虑

I have my infrastructure set up to leverage the --harmony flag. Should I remove it?

The current behavior of the --harmony flag on Node.js is to enable staged features only. After all, it is now a synonym of --es_staging. As mentioned above, these are completed features that have not been considered stable yet. If you want to play safe, especially on production environments, consider removing this runtime flag until it ships by default on V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for further Node.js upgrades to break your code if V8 changes their semantics to more closely follow the standard.

总的来说,建议除了shipping 至 V8的 的特性都不要用,具体的定义:

All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged, and in progress features:

  • All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.
  • Staged features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag: --harmony.
  • In progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.

官网其他有意思的内容

Fork 和 merge 应用

把一个实验性的功能作为一个分支Fork出来,实验成功后又Merge进主干

2014

  • The Big Fork: io.js is a major fork of Node.js, with the goal of introducing ES6 support and moving faster

2015

  • The Node.js Foundation is born
  • IO.js is merged back into Node.js
  • npm introduces private modules
  • Node.js 4 (versions 1, 2 and 3 never previously released)

TODO

相关文章:

  • 番茄ToDo语句精选
  • 树状数组。 数组修改某个元素的数值/求出前n个元素的和,需要在一百毫秒处理上百万个数字
  • 【操作系统】第一章 计算机系统概述
  • 【Vue】Vue的Mustache插值语法、v-bind指令
  • Android7.1.1系统,Toast的Exception: android.view.WindowManager$BadTokenException解决
  • TiKV 监控指标详解
  • 嵌入式系统开发笔记92:感受开源之美
  • VLC 编译安装 [for android, linux, windows]
  • 字节内部私藏的数据结构与算法刷题笔记,太顶了熬夜刷上头
  • 前端性能优化方法与实战开篇词 开启刻意练习之路,进阶前端性能技术专家
  • 实战java高并发程序设计(第2版)学习(1-3)
  • TiCDC 重要监控指标详解
  • T1063 最大跨度值(信息学一本通C++)
  • JavaSE 一些技巧 03——Stream流常用API
  • VMware安装Android-x86示例
  • php的引用
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • go语言学习初探(一)
  • pdf文件如何在线转换为jpg图片
  • PHP 的 SAPI 是个什么东西
  • React-Native - 收藏集 - 掘金
  • supervisor 永不挂掉的进程 安装以及使用
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • vue.js框架原理浅析
  • 技术攻略】php设计模式(一):简介及创建型模式
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 小试R空间处理新库sf
  • 学习JavaScript数据结构与算法 — 树
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 如何用纯 CSS 创作一个货车 loader
  • ​【数据结构与算法】冒泡排序:简单易懂的排序算法解析
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • (第一天)包装对象、作用域、创建对象
  • (二)学习JVM —— 垃圾回收机制
  • (十六)串口UART
  • (四)库存超卖案例实战——优化redis分布式锁
  • (五)MySQL的备份及恢复
  • .bat批处理(六):替换字符串中匹配的子串
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .Net MVC + EF搭建学生管理系统
  • .Net Remoting常用部署结构
  • .NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 WeakDictionary)
  • @Bean, @Component, @Configuration简析
  • @基于大模型的旅游路线推荐方案
  • [2544]最短路 (两种算法)(HDU)
  • [AS3]URLLoader+URLRequest+JPGEncoder实现BitmapData图片数据保存
  • [BT]小迪安全2023学习笔记(第15天:PHP开发-登录验证)
  • [c语言]小课堂 day2
  • [Docker]十一.Docker Swarm集群raft算法,Docker Swarm Web管理工具
  • [IE9] GPU硬件加速到底是实用创新还是噱头
  • [IE编程] 如何在IE8 下调试BHO控件/工具栏(调试Tab进程)
  • [Interview]Java 面试宝典系列之 Java 多线程
  • [Linux]进程创建➕进程终止
  • [Linux打怪升级之路]-vim编辑器(看就能马上操作噢)
  • [NOIP2015] 运输计划