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?










0















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?










share|improve this question


























    0















    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?










    share|improve this question
























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 17:28









      William JonesWilliam Jones

      98111




      98111






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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...






          share|improve this answer























          • 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












          • Can you access your file through the url? Something like http://localhost:3000/js/script.js?

            – Rashomon
            Mar 7 at 18:40










          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
          );



          );













          draft saved

          draft discarded


















          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









          0














          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...






          share|improve this answer























          • 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












          • Can you access your file through the url? Something like http://localhost:3000/js/script.js?

            – Rashomon
            Mar 7 at 18:40















          0














          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...






          share|improve this answer























          • 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












          • Can you access your file through the url? Something like http://localhost:3000/js/script.js?

            – Rashomon
            Mar 7 at 18:40













          0












          0








          0







          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...






          share|improve this answer













          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...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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

















          • 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












          • Can you access your file through the url? Something like http://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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived