简体   繁体   中英

Change of directory with node.js

Hello then I state that something very strange happens to me, which had never happened to me. So I have a node.js application that runs perfectly on a centos server! Once the application has been loaded on the server, boot with node server.js and everything is working on perfection! As a reboot I set a cron to start the server node with this syntax:

**@reboot node /var/www/html/app/main.js**

the problem is that when I restart the machine the cron starts correctly node.js but when I have to do the change of directory below I have this error:

Node.js Code:

process.chdir('./Model');

Directory Tree:

/var/www/html/app

/var/www/html/app/main.js

/var/www/html/app/Model

Error: ENOENT: no such file or directory, uv_chdir

Please refer to this question .

Just adding a node command in cron won't work. You need to do cd into your project root dir and execute node command.

What is current working directory of your process? Try console.log( Starting directory: ${process.cwd()} ); to see if it is /var/www/html/app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM