• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

node.js和express打包部署环境

武飞扬头像
weixin_46476340
帮助1

1.新建文件夹,使用vscode打开
2.在终端执行npm init

PS D:\ChromeCoreDownloads\vsc\demo> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (demo) xiaoming_test_serve//取名字

接下来一直回车
3.安装 D:\ChromeCoreDownloads\vsc\demo> npm i express

新建主文件server.js学新通
4.server.js编写完成后PS D:\ChromeCoreDownloads\vsc\demo> node server
5.新建static文件放入打包好的文件
6.http://localhost:5005/运行即可
7.解决mode:‘history’,刷新问题,在服务器中安装npm i connect-history-api-fallback,在server.js中引用

const express = require('express')
const history = require('connect-history-api-fallback');

const app = express()
app.use(history())
app.use(express.static(__dirname '/static'))

在使用静态资源前引用

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkfkf
系列文章
更多 icon
同类精品
更多 icon
继续加载