美文网首页
第二节:Node+Express部署

第二节:Node+Express部署

作者: 林玲玲的笔记 | 来源:发表于2021-11-20 17:55 被阅读0次

1.通过express命令创建一个新的Express 工程目录 express-router,命令如下:

express -e express-router

2.进入工程目录,通过npm命令安装下载依赖

npm install

3.运行项目

npm start

4.如果发生以下错误:

const utf8Encoder = new TextEncoder();
                    ^
ReferenceError: TextEncoder is not defined

则:在安装好的node_modules中找到“node_modules\whatwg-url\lib\encoding.js”
修改为如下:

"use strict";
var util= require('util');
const utf8Encoder = new util.TextEncoder();
const utf8Decoder = new util.TextEncoder("utf-8", { ignoreBOM: true });

function utf8Encode(string) {
  return utf8Encoder.encode(string);
}

function utf8DecodeWithoutBOM(bytes) {
  return utf8Decoder.decode(bytes);
}

module.exports = {
  utf8Encode,
  utf8DecodeWithoutBOM
};

5.安装“nodemon”实时更新模块,该模块可以运行一次,在编辑器中代码更新,即更新服务。

npm install nodemon

安装完,在“package.json中修改启动start”为:

 "scripts": {
    "start": "nodemon ./bin/www"
  },

6.运行:npm start , 在浏览器中打开地址:http://localhost:3000

相关文章

网友评论

      本文标题:第二节:Node+Express部署

      本文链接:https://www.haomeiwen.com/subject/pblmtrtx.html