目 录CONTENT

文章目录

node搭建本地HTML网站

GrantLi
2023-05-31 / 0 评论 / 0 点赞 / 459 阅读 / 2313 字 / 正在检测是否收录...

依赖

安装curl

sudo apt install curl

安装nvm

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

# 激活nvm
source ~/.nvm/nvm.sh

# 安装node.js 、npm
nvm install node

# 安装 express
npm install express -g

npm install   express-generator -g

配置

在html上级目录创建expressHtml.js文件,内容如下:

var express = require("express");
var app = express();
app.use(express.static("html")).listen(809);

运行expressHtml.js文件:

cd path_to_expressHtml.js

npm install express
node expressHtml.js

成功启动,在浏览器中输入localhost:809/index.html即可访问

开机自启动

新增nav2.service

sudo vi  /etc/systemd/system/nav2.service

添加如下内容:

[Unit]
Description=nav2
[Service]
WorkingDirectory=/path_to_navigation.ros.org/_build
ExecStart=/usr/local/bin/node expressHtml.js
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

启动配置:

sudo systemctl enable nav2.service

sudo systemctl start nav2.service
# 查看服务状态
systemctl status nav2.service
0

评论区