开源跨平台的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.
文件命名为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
nvm
https://github.com/nvm-sh/nvm
I would recommend you to have a good grasp of the main JavaScript concepts before diving into Node.js:
官网强调,要深入到node.js中,最好熟悉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:
--harmony
.把一个实验性的功能作为一个分支Fork出来,实验成功后又Merge进主干