1.Node.js入门







如果还是报错可能终端没选好,下面是终端选择,但是我这里是可以运行。



2.fs模块-读写文件




3.path模块-路径处理


4.案例-压缩前端html

就是压缩代码

步骤

5.URL中的端口号



6.http模块-创建Web服务


7.案例-浏览时钟


            
            
              javascript
              
              
            
          
          /**
 * 目标:基于 Web 服务,开发提供网页资源的功能
 * 步骤:
 *  1. 基于 http 模块,创建 Web 服务
 *  2. 使用 req.url 获取请求资源路径,并读取 index.html 里字符串内容返回给请求方
 *  3. 其他路径,暂时返回不存在提示
 *  4. 运行 Web 服务,用浏览器发起请求
 */
const fs = require('fs')
const path = require('path')
// 1. 基于 http 模块,创建 Web 服务
const http = require('http')
const server = http.createServer()
server.on('request', (req, res) => {
  // 2. 使用 req.url 获取请求资源路径,并读取 index.html 里字符串内容返回给请求方
  if (req.url === '/index.html') {
    fs.readFile(path.join(__dirname, 'dist/index.html'), (err, data) => {
      res.setHeader('Content-Type', 'text/html;charset=utf-8')
      res.end(data.toString())
    })
  } else {
    // 3. 其他路径,暂时返回不存在提示
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    res.end('你要访问的资源路径不存在')
  }
})
server.listen(8080, () => {
  console.log('Web 服务启动成功了')
})8.模块化简介



 9.ECMAScript标准-默认导出和导入
9.ECMAScript标准-默认导出和导入



 10.ECMAScript标准-命名导出和导入
 10.ECMAScript标准-命名导出和导入



11.包的概念



12.npm软件包管理器


步骤:

生成package.json包

添加包

使用包


13.npm安装所有依赖

eg
包拿来缺少node_modules

执行命令npm i

运行文件得出结果


14.npm全局软件包-nodemon



执行完后可继续修改值,然后保存会自动生成结果


15.Node.js概念和常用命令总结



