How to get the project root directory in koa2

_ _ dirname is the current directory, not the project root.

the initial question is that I want to put all the uploaded files in the upload directory under the root directory of the project, but how do I get this root directory?

consider storing _ _ dirname in the properties of app in app.js in the root directory, but how to access app in subsequent middleware? Some middleware can wrap app when calling, such as router (app), but some don"t, only ctx. Can you access app from ctx?

Thank you.

Jun.20,2022

process.cwd () gets the root directory where node works, and files can be obtained through relative paths.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30c99-40d83.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30c99-40d83.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?