res.sendfile(""; climate I obtain a server console warning

express deprecated res.sendfile: use res.sendFile instead

but it works fine top top the client side.

You are watching: Typeerror: path must be absolute or specify root to res.sendfile

But as soon as I change it to

res.sendFile("";I gain an error

TypeError: path should be pure or specify source to res.sendFile

and index1.html is not rendered.

I am unable to number out what the absolute path is. I have public brochure at the same level as server.js. I am law the res.sendFile from with server.js. Ns have additionally declared app.use(express.static(path.join(__dirname, "";

Adding my magazine structure:

/Users/sj/test/ is the absolute course to it is in specified here ?

I" utilizing Express 4.x.


The express.static middleware is separate from res.sendFile, therefore initializing it through an absolute course to your public catalog won" execute anything come res.sendFile. You have to use an pure path directly with res.sendFile. There are two straightforward ways to execute it:

res.sendFile(path.join(__dirname, "", "";res.sendFile("", root: path.join(__dirname, "" );

Note: __dirname return the directory that the currently executing manuscript is in. In your case, that looks prefer server.js is in app/. So, to acquire to public, you" need ago out one level first: ../public/index1.html.

Note: path is a integrated module that needs to be forced for the above code come work: var path = require("";

Saturday, June 5, 2021

answer 7 Months ago

you need to use a config document that will certainly be contained in each record first line, for example your application look favor this

root / app / Plugins

inside your root dir : app-config.php

if ( !defined("" ) define("", dirname(__FILE__) . "";now, intend you have to incorporate a plugin file, so

inside your Plugin dir : my-plugin.php

require_once "";now everything listed below this line have the right to use ABSPATH

example execute you desire to pack an image

now, the thing is much more simple if your app is designed to automatically load some records like

plugin-widget-1.phpso that every little thing inside this file or any kind of other record loaded by the my-plugin.php paper can use the ABSPATH without encompass each time the app-config.php file.

See more: Sniffling You Are All So Ugly Meme, #You Are All So Ugly On Tumblr

with this in mind you deserve to have every the short-hand friend want right into the app-config.php example

define("", ABSPATH. "";define("", ABSPATH. "";define("", ABSPATH. "";, now that you have actually all defined, if you require to move a file, let" say one folder forward example:

root / app / Plugins / Utils

just inlucde require_once "";

obviously i expect that you are not transforming paths each time =) quiet if you have to do so is always much more simple to adjust one record inclusion instead of hundreds.