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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현