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;








1















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









share|improve this question


























  • 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

















1















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









share|improve this question


























  • 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













1












1








1








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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
















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












2 Answers
2






active

oldest

votes


















1
















it should be app.use('/', express.static('views/statics'));
check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot






share|improve this answer



























  • 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


















1
















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.






share|improve this answer



























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



    );














    draft saved

    draft discarded
















    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









    1
















    it should be app.use('/', express.static('views/statics'));
    check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot






    share|improve this answer



























    • 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















    1
















    it should be app.use('/', express.static('views/statics'));
    check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot






    share|improve this answer



























    • 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













    1














    1










    1









    it should be app.use('/', express.static('views/statics'));
    check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot






    share|improve this answer















    it should be app.use('/', express.static('views/statics'));
    check the working model here : https://repl.it/@VikashSingh1/SlategrayDeadRobot







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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

















    • 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













    1
















    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.






    share|improve this answer





























      1
















      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.






      share|improve this answer



























        1














        1










        1









        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 7:44









        Hasan RazaHasan Raza

        151 silver badge6 bronze badges




        151 silver badge6 bronze badges































            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%2f55391788%2fhow-to-mount-root-to-a-directory-in-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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript