当前位置:   article > 正文

node.js与express打包部署环境

express打包部署

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//取名字
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

接下来一直回车
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'))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在使用静态资源前引用

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/120291
推荐阅读
相关标签
  

闽ICP备14008679号