Can someone please tell me how to read the following: /.(js)$/










0















I'm trying to understand some webserver code I found online and the part right after the "else if" is the only part I don't understand. (I just started learning this stuff). Thanks






var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);












share|improve this question

















  • 1





    It's a regular expression literal.

    – Pointy
    Nov 15 '18 at 20:32











  • Possible duplicate of Learning Regular Expressions

    – Sean Pianka
    Nov 15 '18 at 20:42















0















I'm trying to understand some webserver code I found online and the part right after the "else if" is the only part I don't understand. (I just started learning this stuff). Thanks






var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);












share|improve this question

















  • 1





    It's a regular expression literal.

    – Pointy
    Nov 15 '18 at 20:32











  • Possible duplicate of Learning Regular Expressions

    – Sean Pianka
    Nov 15 '18 at 20:42













0












0








0








I'm trying to understand some webserver code I found online and the part right after the "else if" is the only part I don't understand. (I just started learning this stuff). Thanks






var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);












share|improve this question














I'm trying to understand some webserver code I found online and the part right after the "else if" is the only part I don't understand. (I just started learning this stuff). Thanks






var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);








var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);





var path = url.parse(req.url).pathname;

// Managing the root route
if (path == '/')
index = fs.readFile(__dirname+'/public/index.html',
function(error,data)

//do stuff...
);
// Managing the route for the javascript files
else if( /.(js)$/.test(path) ) {
index = fs.readFile(__dirname+'/public'+path,
function(error,data)

//do stuff...
);






javascript linux command-line






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 20:31









CollinACollinA

12




12







  • 1





    It's a regular expression literal.

    – Pointy
    Nov 15 '18 at 20:32











  • Possible duplicate of Learning Regular Expressions

    – Sean Pianka
    Nov 15 '18 at 20:42












  • 1





    It's a regular expression literal.

    – Pointy
    Nov 15 '18 at 20:32











  • Possible duplicate of Learning Regular Expressions

    – Sean Pianka
    Nov 15 '18 at 20:42







1




1





It's a regular expression literal.

– Pointy
Nov 15 '18 at 20:32





It's a regular expression literal.

– Pointy
Nov 15 '18 at 20:32













Possible duplicate of Learning Regular Expressions

– Sean Pianka
Nov 15 '18 at 20:42





Possible duplicate of Learning Regular Expressions

– Sean Pianka
Nov 15 '18 at 20:42












2 Answers
2






active

oldest

votes


















2














It allows you to test against regular expresions.
Heres the MDN on how it works.



In your example, it's checking if the path ends in .js






share|improve this answer






























    1














    Regular expressions produce non strict match against the string.
    Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case






    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/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%2f53327481%2fcan-someone-please-tell-me-how-to-read-the-following-js%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









      2














      It allows you to test against regular expresions.
      Heres the MDN on how it works.



      In your example, it's checking if the path ends in .js






      share|improve this answer



























        2














        It allows you to test against regular expresions.
        Heres the MDN on how it works.



        In your example, it's checking if the path ends in .js






        share|improve this answer

























          2












          2








          2







          It allows you to test against regular expresions.
          Heres the MDN on how it works.



          In your example, it's checking if the path ends in .js






          share|improve this answer













          It allows you to test against regular expresions.
          Heres the MDN on how it works.



          In your example, it's checking if the path ends in .js







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 20:36









          SpeedOfRoundSpeedOfRound

          629314




          629314























              1














              Regular expressions produce non strict match against the string.
              Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case






              share|improve this answer



























                1














                Regular expressions produce non strict match against the string.
                Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case






                share|improve this answer

























                  1












                  1








                  1







                  Regular expressions produce non strict match against the string.
                  Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case






                  share|improve this answer













                  Regular expressions produce non strict match against the string.
                  Besides MSDN @SpeedOfRound mentioned about it would be useful to play with this service to get the better understanding on your exact case







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 23:11









                  Case TrackerCase Tracker

                  212




                  212



























                      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%2f53327481%2fcan-someone-please-tell-me-how-to-read-the-following-js%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

                      27

                      Top Tejano songwriter Luis Silva dead of heart attack at 64

                      Category:Rhetoric