Can someone please tell me how to read the following: /.(js)$/
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...
);javascript linux command-line
add a comment |
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...
);javascript linux command-line
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
add a comment |
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...
);javascript linux command-line
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
javascript linux command-line
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 15 '18 at 20:36
SpeedOfRoundSpeedOfRound
629314
629314
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 15 '18 at 23:11
Case TrackerCase Tracker
212
212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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