运行 一个 NodeJS 应用在启动时自动启动

Running a NodeJS app automaticaly at the start up

我有一个小的 NodeJS 应用程序可以访问 MongoDB 数据库并获取一些数据以便显示在 index.html 文件中。我 运行 它在 Ubuntu Mate 18.04.2 OS 上 Raspberry Pi B+

我 运行 NodeJS 应用程序包含以下行:

node /routeofmyapp/index.js

然后服务器启动,我可以转到 index.html 文件并检查显示的数据。

我想在项目中做的下一件事是 index.js 在系统启动时自动执行,而无需启动控制台终端。

我该怎么做?

提前致谢。

编辑 sudo nano /home/pi/.bashrc 文件。

转到脚本的最后一行并添加:

echo Running at boot 
sudo node /routeofmyapp/index.js

然后保存并重启树莓派:

sudo reboot