How to mount root to a directory in express?How do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsHow to decide when to use Node.js?How to exit in Node.jsHow to get GET (query string) variables in Express.js on Node.js?Express js static relative parent directoryhow to access node_module directory which was out side the static content serving folderFiles won't load if in root directory?Purpose of a virtual path prefix in ExpressHow to make express serve static files from another upper directory?
Owner keeps cutting corners and poaching workers for his other company
Examples where "thin + thin = nice and thick"
Is mountain bike good for long distances?
I won a car in a poker game. How is that taxed in Canada?
Why did Tony's Arc Reactor do this?
Why does PAUSE key have a long make code and no break code?
What makes an ending "happy"?
Friend is very nitpicky about side comments I don't intend to be taken too seriously
What's the biggest difference between these two photos?
is it possible to change a material depending on whether it is intersecting with another object?
Did "Dirty Harry" feel lucky?
Problem with listing a directory to grep
Can you pop microwave popcorn on a stove?
Did the Byzantines ever attempt to move their capital to Rome?
Short story: Interstellar inspector senses "off" nature of planet hiding aggressive culture
Why does low tire pressure decrease fuel economy?
Is it right to use the ideas of non-winning designers in a design contest?
What makes things real?
How to convert P2O5 concentration to H3PO4 concentration?
When calculating averages, why can we treat exploding die as if they're independent?
Capacitors with same voltage, same capacitance, same temp, different diameter?
Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?
Infinitely many primes
Is future tense in English really a myth?
How to mount root to a directory in express?
How do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsHow to decide when to use Node.js?How to exit in Node.jsHow to get GET (query string) variables in Express.js on Node.js?Express js static relative parent directoryhow to access node_module directory which was out side the static content serving folderFiles won't load if in root directory?Purpose of a virtual path prefix in ExpressHow to make express serve static files from another upper directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to mount a particular directory in an app to root. The structure of my app is
/app
/server.js
/views
/statics
/index.html
/partials
/public
/javascript
/css
/images
I want the static to be served as root so I can access index.html at localhostL:4001/index.html instead of localhostL:4001/static/views/index/html
I have tried to use express.statics. However, it didn't work.
in server.js
app.use(express.static('public'));
app.use('/', express.static('views/statics'));
node.js express
add a comment |
I am trying to mount a particular directory in an app to root. The structure of my app is
/app
/server.js
/views
/statics
/index.html
/partials
/public
/javascript
/css
/images
I want the static to be served as root so I can access index.html at localhostL:4001/index.html instead of localhostL:4001/static/views/index/html
I have tried to use express.statics. However, it didn't work.
in server.js
app.use(express.static('public'));
app.use('/', express.static('views/statics'));
node.js express
why not serve asapp.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001
– 1565986223
Mar 28 at 7:40
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35
add a comment |
I am trying to mount a particular directory in an app to root. The structure of my app is
/app
/server.js
/views
/statics
/index.html
/partials
/public
/javascript
/css
/images
I want the static to be served as root so I can access index.html at localhostL:4001/index.html instead of localhostL:4001/static/views/index/html
I have tried to use express.statics. However, it didn't work.
in server.js
app.use(express.static('public'));
app.use('/', express.static('views/statics'));
node.js express
I am trying to mount a particular directory in an app to root. The structure of my app is
/app
/server.js
/views
/statics
/index.html
/partials
/public
/javascript
/css
/images
I want the static to be served as root so I can access index.html at localhostL:4001/index.html instead of localhostL:4001/static/views/index/html
I have tried to use express.statics. However, it didn't work.
in server.js
app.use(express.static('public'));
app.use('/', express.static('views/statics'));
node.js express
node.js express
edited Mar 28 at 7:23
Kittichote Kamalapirat
asked Mar 28 at 6:58
Kittichote KamalapiratKittichote Kamalapirat
665 bronze badges
665 bronze badges
why not serve asapp.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001
– 1565986223
Mar 28 at 7:40
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35
add a comment |
why not serve asapp.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001
– 1565986223
Mar 28 at 7:40
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35
why not serve as
app.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001– 1565986223
Mar 28 at 7:40
why not serve as
app.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001– 1565986223
Mar 28 at 7:40
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35
add a comment |
2 Answers
2
active
oldest
votes
it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
add a comment |
Currently you are using relative path to serve static files instead of this you can use absolute path for serving files like this
app.use(express.statics(path.join(__dirname, 'views/statics'));
This will solve your problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391788%2fhow-to-mount-root-to-a-directory-in-express%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
add a comment |
it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
add a comment |
it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot
it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot
edited Mar 28 at 7:25
answered Mar 28 at 7:16
Vikash SinghVikash Singh
1,4522 gold badges8 silver badges25 bronze badges
1,4522 gold badges8 silver badges25 bronze badges
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
add a comment |
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
sorry, I typed the directory structure wrongly.
– Kittichote Kamalapirat
Mar 28 at 7:22
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
i have updated the solution in the link provided.
– Vikash Singh
Mar 28 at 7:25
add a comment |
Currently you are using relative path to serve static files instead of this you can use absolute path for serving files like this
app.use(express.statics(path.join(__dirname, 'views/statics'));
This will solve your problem.
add a comment |
Currently you are using relative path to serve static files instead of this you can use absolute path for serving files like this
app.use(express.statics(path.join(__dirname, 'views/statics'));
This will solve your problem.
add a comment |
Currently you are using relative path to serve static files instead of this you can use absolute path for serving files like this
app.use(express.statics(path.join(__dirname, 'views/statics'));
This will solve your problem.
Currently you are using relative path to serve static files instead of this you can use absolute path for serving files like this
app.use(express.statics(path.join(__dirname, 'views/statics'));
This will solve your problem.
answered Mar 28 at 7:44
Hasan RazaHasan Raza
151 silver badge6 bronze badges
151 silver badge6 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391788%2fhow-to-mount-root-to-a-directory-in-express%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why not serve as
app.get('/', (req, res) => res.sendFile('index'))
after mounting the view middleware? That way your html will be served at localhost:4001– 1565986223
Mar 28 at 7:40
I think that by using app.use('/', express.static('views/statics')); the . app.get('/', (req, res) => res.sendFile('index')) is already included, no?
– Kittichote Kamalapirat
Mar 28 at 7:45
you can use 'view engine' to parse and render 'html', that way you don't have to access 'html' files as, localhostL:4001/static/views/index/html
– 1565986223
Mar 28 at 7:50
Are there any other ways you can do without using ' view engine'?
– Kittichote Kamalapirat
Mar 28 at 8:35