node项目部署到ftp

2022-03-15 05:00:00 # 清学小记

简介

对于node项目build构建完成后,可通过npm插件ftp-deploy部署上传到ftp服务器

示例代码

1
var FtpDeploy = require("ftp-deploy");var ftpDeploy = new FtpDeploy();var config = {    user: "user",    // Password optional, prompted if none given    password: "password",    host: "ftp.someserver.com",    port: 21,    localRoot: __dirname + "/local-folder",    remoteRoot: "/public_html/remote-folder/",    // include: ["*", "**/*"],      // this would upload everything except dot files    include: ["*.php", "dist/*", ".*"],    // e.g. exclude sourcemaps, and ALL files in node_modules (including dot files)    exclude: ["dist/**/*.map", "node_modules/**", "node_modules/**/.*", ".git/**"],    // delete ALL existing files at destination before uploading, if true    deleteRemote: false,    // Passive mode is forced (EPSV command is not sent)    forcePasv: true,    // use sftp or ftp    sftp: false};ftpDeploy    .deploy(config)    .then(res => console.log("finished:", res))    .catch(err => console.log(err));

补充

  • ftp配置信息可用环境变量存储、调用;
  • 脚本执行时机可区分开发环境

插件

  • 查看 ftp-deploy
  • 安装 npm install --save-dev ftp-deploy
  • 使用
1
"scripts": {    "deploy": "node deploy"},
  • 本文作者 北门清燕
  • 本文链接 node项目部署到ftp
  • 发表日期 2022-03-15 05:00:00
  • 更新日期 2022-03-15 05:00:00
  • 版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!