Change static folder - express2019 Community Moderator ElectionHow to change an element's class with JavaScript?How do you use a variable in a regular expression?Change an HTML5 input's placeholder color with CSSSimple static HTML server in NodeWhy this error coming while running nodejs server?Code doesn't serve my static html files in the publlic folderHow to use react within Express?Send Multiple Static Files with Express Routerexpress static: serve pages with dynamic contentHow to make express serve static files from another upper directory?
Do US professors/group leaders only get a salary, but no group budget?
Is it possible to stack the damage done by the Absorb Elements spell?
What is the English word for a graduation award?
What favor did Moody owe Dumbledore?
How could an airship be repaired midflight?
Optimising a list searching algorithm
What does "^L" mean in C?
Could Sinn Fein swing any Brexit vote in Parliament?
Word for flower that blooms and wilts in one day
Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?
Do I need to be arrogant to get ahead?
Am I eligible for the Eurail Youth pass? I am 27.5 years old
Can a wizard cast a spell during their first turn of combat if they initiated combat by releasing a readied spell?
Violin - Can double stops be played when the strings are not next to each other?
Brake pads destroying wheels
In what cases must I use 了 and in what cases not?
Loading the leaflet Map in Lightning Web Component
Does .bashrc contain syntax errors?
What can I do if I am asked to learn different programming languages very frequently?
Can a medieval gyroplane be built?
Comment Box for Substitution Method of Integrals
Should I use acronyms in dialogues before telling the readers what it stands for in fiction?
Generic TVP tradeoffs?
Print a physical multiplication table
Change static folder - express
2019 Community Moderator ElectionHow to change an element's class with JavaScript?How do you use a variable in a regular expression?Change an HTML5 input's placeholder color with CSSSimple static HTML server in NodeWhy this error coming while running nodejs server?Code doesn't serve my static html files in the publlic folderHow to use react within Express?Send Multiple Static Files with Express Routerexpress static: serve pages with dynamic contentHow to make express serve static files from another upper directory?
I'm making a NodeJS app with express, and I would like to send the user to another page in an app.post
function.
I know that you can serve pages by using something like this: app.use(express.static('client/home'));
and this is working in my app, but when I put this into my app.post
as follows below, the page just says "localhost didn't send any data".
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
);
If I add res.end('');
after app.use
, then the page doesn't crash but I'm met with a blank screen.
How can I get Express to serve the HTML in the client/school
folder?
javascript html node.js express
add a comment |
I'm making a NodeJS app with express, and I would like to send the user to another page in an app.post
function.
I know that you can serve pages by using something like this: app.use(express.static('client/home'));
and this is working in my app, but when I put this into my app.post
as follows below, the page just says "localhost didn't send any data".
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
);
If I add res.end('');
after app.use
, then the page doesn't crash but I'm met with a blank screen.
How can I get Express to serve the HTML in the client/school
folder?
javascript html node.js express
add a comment |
I'm making a NodeJS app with express, and I would like to send the user to another page in an app.post
function.
I know that you can serve pages by using something like this: app.use(express.static('client/home'));
and this is working in my app, but when I put this into my app.post
as follows below, the page just says "localhost didn't send any data".
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
);
If I add res.end('');
after app.use
, then the page doesn't crash but I'm met with a blank screen.
How can I get Express to serve the HTML in the client/school
folder?
javascript html node.js express
I'm making a NodeJS app with express, and I would like to send the user to another page in an app.post
function.
I know that you can serve pages by using something like this: app.use(express.static('client/home'));
and this is working in my app, but when I put this into my app.post
as follows below, the page just says "localhost didn't send any data".
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
);
If I add res.end('');
after app.use
, then the page doesn't crash but I'm met with a blank screen.
How can I get Express to serve the HTML in the client/school
folder?
javascript html node.js express
javascript html node.js express
asked Mar 7 at 17:28
William JonesWilliam Jones
98111
98111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I had to add a res.sendFile
after app.use
. The function is now as follows:
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
res.sendFile(path.join(__dirname, '/client/school/index.html'));
);
The reason I didn't add this is because it wasn't needed at the start. Why is this, by the way?
**Edit: ** When I remove the app.use
in the POST method (leaving me with just res.sendFile
, the page still works as intended. So why do I need app.use
? I thought it was to serve all the files in the folder together, i.e. HTML, CSS and JS, as just using res.sendFile just gives you the bare HTML.
I'm really confused now...
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought justres.sendFile
only showed bare HTML though.
– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something likehttp://localhost:3000/js/script.js
?
– Rashomon
Mar 7 at 18:40
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/3.0/"u003ecc by-sa 3.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%2f55049698%2fchange-static-folder-express%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I had to add a res.sendFile
after app.use
. The function is now as follows:
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
res.sendFile(path.join(__dirname, '/client/school/index.html'));
);
The reason I didn't add this is because it wasn't needed at the start. Why is this, by the way?
**Edit: ** When I remove the app.use
in the POST method (leaving me with just res.sendFile
, the page still works as intended. So why do I need app.use
? I thought it was to serve all the files in the folder together, i.e. HTML, CSS and JS, as just using res.sendFile just gives you the bare HTML.
I'm really confused now...
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought justres.sendFile
only showed bare HTML though.
– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something likehttp://localhost:3000/js/script.js
?
– Rashomon
Mar 7 at 18:40
add a comment |
I had to add a res.sendFile
after app.use
. The function is now as follows:
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
res.sendFile(path.join(__dirname, '/client/school/index.html'));
);
The reason I didn't add this is because it wasn't needed at the start. Why is this, by the way?
**Edit: ** When I remove the app.use
in the POST method (leaving me with just res.sendFile
, the page still works as intended. So why do I need app.use
? I thought it was to serve all the files in the folder together, i.e. HTML, CSS and JS, as just using res.sendFile just gives you the bare HTML.
I'm really confused now...
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought justres.sendFile
only showed bare HTML though.
– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something likehttp://localhost:3000/js/script.js
?
– Rashomon
Mar 7 at 18:40
add a comment |
I had to add a res.sendFile
after app.use
. The function is now as follows:
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
res.sendFile(path.join(__dirname, '/client/school/index.html'));
);
The reason I didn't add this is because it wasn't needed at the start. Why is this, by the way?
**Edit: ** When I remove the app.use
in the POST method (leaving me with just res.sendFile
, the page still works as intended. So why do I need app.use
? I thought it was to serve all the files in the folder together, i.e. HTML, CSS and JS, as just using res.sendFile just gives you the bare HTML.
I'm really confused now...
I had to add a res.sendFile
after app.use
. The function is now as follows:
app.post('/createSchool', function(req, res)
app.use(express.static('client/school'));
res.sendFile(path.join(__dirname, '/client/school/index.html'));
);
The reason I didn't add this is because it wasn't needed at the start. Why is this, by the way?
**Edit: ** When I remove the app.use
in the POST method (leaving me with just res.sendFile
, the page still works as intended. So why do I need app.use
? I thought it was to serve all the files in the folder together, i.e. HTML, CSS and JS, as just using res.sendFile just gives you the bare HTML.
I'm really confused now...
answered Mar 7 at 17:39
William JonesWilliam Jones
98111
98111
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought justres.sendFile
only showed bare HTML though.
– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something likehttp://localhost:3000/js/script.js
?
– Rashomon
Mar 7 at 18:40
add a comment |
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought justres.sendFile
only showed bare HTML though.
– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something likehttp://localhost:3000/js/script.js
?
– Rashomon
Mar 7 at 18:40
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
Does the html need extra files (CSS, JS)? If so, they should be at your static folder ( that's the way it works, at least...)
– Rashomon
Mar 7 at 17:59
The HTML does need extra files, and yes, they are in the same folder. I thought just
res.sendFile
only showed bare HTML though.– William Jones
Mar 7 at 18:02
The HTML does need extra files, and yes, they are in the same folder. I thought just
res.sendFile
only showed bare HTML though.– William Jones
Mar 7 at 18:02
Can you access your file through the url? Something like
http://localhost:3000/js/script.js
?– Rashomon
Mar 7 at 18:40
Can you access your file through the url? Something like
http://localhost:3000/js/script.js
?– Rashomon
Mar 7 at 18:40
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%2f55049698%2fchange-static-folder-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