Linux installs nodejs online and configures scheduled tasks

foreword

After the installation last redisnight, the reminder was invaded as a springboard machine, and I didn’t care about it at the time. There was nothing urgent and important on that machine, so I hung up two nodescheduled tasks, but this morning I found that the scheduled tasks were not triggered. The wget, curl, and other commands in the server nodeare all invalid. It seems that the server has been cleaned in depth, and even the scheduled tasks are gone.

insert image description here

After reinstalling the system, reinstall it nodeand configure the scheduled tasks.

install node

16.17.0Install the long-term support version here

Download the installation package

Execute the download command to download the compressed package

wget https://cdn.npmmirror.com/binaries/node/v16.17.0/node-v16.17.0-linux-x64.tar.xz

Unzip the compressed package

tar -xvf node-v16.17.0-linux-x64.tar.xz

configure node

nodeMove the file under the current directory /usr/localand rename it tonode

mv node-v16.17.0-linux-x64 /usr/local/node

nodeEnvironment variables configured after adjusting the directory

vim /etc/profile

The configuration file is shown in the figure below

insert image description here
Add the following configuration at the bottom

export PATH=$PATH:/usr/local/node/bin

insert image description here

Execute the refresh command after saving to make the environment variable take effect immediately

source /etc/profile

verify node

After configuring the environment variables, you can view nodethe version through the following command

node -v
npm -v

The installation is complete as shown below

insert image description here

Configure scheduled tasks

For configuring scheduled tasks , keywords crontabcannot be used directly in the configuration , because they are not recognized, and the specified directory and corresponding execution are required .nodenodebinjs

Point to the command to edit the cron job

crontab -e

In order to verify the expression, select the next minute, 14:25, the actual nodeaddress is /usr/local/node/bin/nodeplus jsthe address, and the timing command is as follows:

* 27 14 * * /usr/local/node/bin/node /usr/local/node/project/an/app.js

insert image description here
Save verification no problem

Supongo que te gusta

Origin blog.csdn.net/AnNanDu/article/details/127223700
Recomendado
Clasificación