NodeJS Express — Serve generated index.html public file without saving it2019 Community Moderator ElectionNodeJS — Fork Child Process with function string instead of fileNodeJS / Express: what is “app.use”?What's the difference between app.use and app.get with express.static?serving static content with a cachall route - expressexpress js not serving static filesWhat's the better approach: serving static files with Express or nginx?Code doesn't serve my static html files in the publlic folderExpress File Serving and Static FilesHow do I serve static files for my node-js server which are in my application root directoryHow to make express serve static files from another upper directory?How to properly serve index.html from node / express app?

If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?

Relationship between sampajanna definitions in SN 47.2 and SN 47.35

Could this Scherzo by Beethoven be considered to be a fugue?

Is Manda another name for Saturn (Shani)?

Print a physical multiplication table

How could a scammer know the apps on my phone / iTunes account?

Have the tides ever turned twice on any open problem?

How to get the n-th line after a grepped one?

Violin - Can double stops be played when the strings are not next to each other?

Examples of transfinite towers

Aluminum electrolytic or ceramic capacitors for linear regulator input and output?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

How to write cleanly even if my character uses expletive language?

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

Adventure Game (text based) in C++

"of which" is correct here?

Can a wizard cast a spell during their first turn of combat if they initiated combat by releasing a readied spell?

How can we have a quark condensate without a quark potential?

How to pronounce "I ♥ Huckabees"?

What favor did Moody owe Dumbledore?

Custom alignment for GeoMarkers

How do you talk to someone whose loved one is dying?

Math equation in non italic font

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?



NodeJS Express — Serve generated index.html public file without saving it



2019 Community Moderator ElectionNodeJS — Fork Child Process with function string instead of fileNodeJS / Express: what is “app.use”?What's the difference between app.use and app.get with express.static?serving static content with a cachall route - expressexpress js not serving static filesWhat's the better approach: serving static files with Express or nginx?Code doesn't serve my static html files in the publlic folderExpress File Serving and Static FilesHow do I serve static files for my node-js server which are in my application root directoryHow to make express serve static files from another upper directory?How to properly serve index.html from node / express app?










0















When using express, the expectation is that you'll serve a public directory.



const app = express();
app.use('/', express.static('./public/'));


Is there a way I could serve a generated file instead? For my application, it would be much more convenient if I could build the index.html directly, then serve that 'file' directly from memory, without having to save it just to then serve it via 'use'.










share|improve this question


























    0















    When using express, the expectation is that you'll serve a public directory.



    const app = express();
    app.use('/', express.static('./public/'));


    Is there a way I could serve a generated file instead? For my application, it would be much more convenient if I could build the index.html directly, then serve that 'file' directly from memory, without having to save it just to then serve it via 'use'.










    share|improve this question
























      0












      0








      0








      When using express, the expectation is that you'll serve a public directory.



      const app = express();
      app.use('/', express.static('./public/'));


      Is there a way I could serve a generated file instead? For my application, it would be much more convenient if I could build the index.html directly, then serve that 'file' directly from memory, without having to save it just to then serve it via 'use'.










      share|improve this question














      When using express, the expectation is that you'll serve a public directory.



      const app = express();
      app.use('/', express.static('./public/'));


      Is there a way I could serve a generated file instead? For my application, it would be much more convenient if I could build the index.html directly, then serve that 'file' directly from memory, without having to save it just to then serve it via 'use'.







      node.js express web-applications server code-generation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 20:44









      KarricKarric

      315215




      315215






















          1 Answer
          1






          active

          oldest

          votes


















          1















          the expectation is that you'll serve a public directory




          I don't think that is the expectation at all. Many applications just use routes instead making a REST micro service.



          There are two ways you can do what you want to do.




          1. Use a templating engine with NodeJS and just res.render() the template. Check this out for more information, even though the article is using .pug you can use these ones as well. Popular ones are ejs, handlebars



            app.get('/', function (req, res) 
            res.render('index', title: 'Hey', message: 'Hello there!' )
            )



          2. Or you can write everything inside res.send() for example:



            app.get('/', function (req, res) 
            //set the appropriate HTTP header
            res.setHeader('Content-Type', 'text/html');

            //send multiple responses to the client
            res.send('<h1>This is the response</h1>');
            );






          share|improve this answer























          • I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

            – Karric
            Mar 7 at 16:12










          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%2f55031856%2fnodejs-express-serve-generated-index-html-public-file-without-saving-it%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









          1















          the expectation is that you'll serve a public directory




          I don't think that is the expectation at all. Many applications just use routes instead making a REST micro service.



          There are two ways you can do what you want to do.




          1. Use a templating engine with NodeJS and just res.render() the template. Check this out for more information, even though the article is using .pug you can use these ones as well. Popular ones are ejs, handlebars



            app.get('/', function (req, res) 
            res.render('index', title: 'Hey', message: 'Hello there!' )
            )



          2. Or you can write everything inside res.send() for example:



            app.get('/', function (req, res) 
            //set the appropriate HTTP header
            res.setHeader('Content-Type', 'text/html');

            //send multiple responses to the client
            res.send('<h1>This is the response</h1>');
            );






          share|improve this answer























          • I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

            – Karric
            Mar 7 at 16:12















          1















          the expectation is that you'll serve a public directory




          I don't think that is the expectation at all. Many applications just use routes instead making a REST micro service.



          There are two ways you can do what you want to do.




          1. Use a templating engine with NodeJS and just res.render() the template. Check this out for more information, even though the article is using .pug you can use these ones as well. Popular ones are ejs, handlebars



            app.get('/', function (req, res) 
            res.render('index', title: 'Hey', message: 'Hello there!' )
            )



          2. Or you can write everything inside res.send() for example:



            app.get('/', function (req, res) 
            //set the appropriate HTTP header
            res.setHeader('Content-Type', 'text/html');

            //send multiple responses to the client
            res.send('<h1>This is the response</h1>');
            );






          share|improve this answer























          • I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

            – Karric
            Mar 7 at 16:12













          1












          1








          1








          the expectation is that you'll serve a public directory




          I don't think that is the expectation at all. Many applications just use routes instead making a REST micro service.



          There are two ways you can do what you want to do.




          1. Use a templating engine with NodeJS and just res.render() the template. Check this out for more information, even though the article is using .pug you can use these ones as well. Popular ones are ejs, handlebars



            app.get('/', function (req, res) 
            res.render('index', title: 'Hey', message: 'Hello there!' )
            )



          2. Or you can write everything inside res.send() for example:



            app.get('/', function (req, res) 
            //set the appropriate HTTP header
            res.setHeader('Content-Type', 'text/html');

            //send multiple responses to the client
            res.send('<h1>This is the response</h1>');
            );






          share|improve this answer














          the expectation is that you'll serve a public directory




          I don't think that is the expectation at all. Many applications just use routes instead making a REST micro service.



          There are two ways you can do what you want to do.




          1. Use a templating engine with NodeJS and just res.render() the template. Check this out for more information, even though the article is using .pug you can use these ones as well. Popular ones are ejs, handlebars



            app.get('/', function (req, res) 
            res.render('index', title: 'Hey', message: 'Hello there!' )
            )



          2. Or you can write everything inside res.send() for example:



            app.get('/', function (req, res) 
            //set the appropriate HTTP header
            res.setHeader('Content-Type', 'text/html');

            //send multiple responses to the client
            res.send('<h1>This is the response</h1>');
            );







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 21:36









          Aritra ChakrabortyAritra Chakraborty

          2,41311015




          2,41311015












          • I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

            – Karric
            Mar 7 at 16:12

















          • I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

            – Karric
            Mar 7 at 16:12
















          I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

          – Karric
          Mar 7 at 16:12





          I'm looking for something similar with forking a child process; directly pass the module instead of a filepath. If you can help with that too, I'd greatly appreciate it: stackoverflow.com/questions/55048262/…

          – Karric
          Mar 7 at 16:12



















          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%2f55031856%2fnodejs-express-serve-generated-index-html-public-file-without-saving-it%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

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко