Answer the question
In order to leave comments, you need to log in
Routing element from express in pure node?
Hello. On the one hand, a simple question appeared, and on the other, a complex one, because I have not yet found an answer to it.
There is a simple server without frameworks that receives the address / user
const http = require('http');
http.createServer((req,res)=>{
if(req.method === 'GET'){
if(req.url === '/user'){
res.writeHead(200,{
'Content-Type': 'text/html'
});
res.end(req.url);
}
}
}).listen(3000);
Answer the question
In order to leave comments, you need to log in
Use regular expressions like if( /\/user(\/\d+)?/.test(req.url))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question