Js path problem

  node.js, question

Project structure

home
 ν app//project logical directory
 ├routes
 ├src
 └app.js
 Public//Static File Directory
 └node_modules

If I need to define the path of the template static file, I need to define it like this:

app.use(express.static(path.join(__dirname, '../public')));

How can absolute paths be used? Use__dirnameAndprocess.cwd()None of these variable methods can achieve results.
Is there any way to get the root directory of the project and use it globally?

Does not work means that the static directory is wrong? Then replace it with:

//suppose this code is written in the home/app directory.
 app.use(express.static(path.resolve(__dirname, '..', 'public')));

It’s really useless to make it into a whole. Stop it