NodeJS

Node.js 原理:
image.png

image.png

REPL环境:
Read-Eval-Print-Loop

什么是REPL?
REPL : Read Eval Print Loop : 交互式解释器。表示电脑的一个环境,类似Windows 系统的终端或Unix/Linux shell,我们可以在终端中输入命令,并接收系统的响应。

image.png

nvm: 可以安装指定版本的nodeJS,也可以指定运行的版本。

基础API:

image.png

image.png

image.png

搭建静态服务器

image.png

image.png

image.png

image.png

  1. const http = require('http');
  2. const fs = require('fs');
  3. const path = require('path');
  4. var server = http.createServer();
  5. server.on('request', function(req, res){
  6. res.setHeader('Content-Type', 'text/html;charset=utf-8');
  7. res.write('<h1>Hello world!<h1>');
  8. res.end();
  9. });
  10. server.listen(8080, function(){
  11. console.log('server is running...');
  12. });