Freya Freya - 11 months ago 53
Node.js Question

Jade page being rendered multiple times

I have a jade page that takes a parameter (username) from the url and renders the info about this user. However, the page is being rendered several times. When I print the url, the first time is seems as if it comes complete (with a username) and the other times it does not. I am using node js and angular to serve the data. Here is my code:

NODE JS: (myuser is a static value of an existing user that I am testing)

router.get('/personel', function (req, res) {
var user_name = req.query['username'];
var fullname= 0;
var fields = ['fullname'];

if(req.url == '/personel?username=myuser'){
attributes: fields,
limit: 1,
where: {username: user_name}
}).then(function (result) {

title : 'Personel',
username: user_name,
fullname: result[0].fullname,

The controller:

Todos.get().success(function(data) {
if ($scope.todosi != undefined) {
$scope.todos = data;
$scope.loading = false;

JADE code:

input(type='text', ng-model='todosi.username', value=username)
td full name
input(type='text', ng-model='todosi.fullname', placeholder=fullname)
button.btn.btn-primary.btn-lg(type='submit', ng-click='createTodo()') Update

So if I load the page as http://localhost:31/apiv2/customer/personel?username=myuser in the browser, the username is empty but fullname has the value of the actual full name.

In the logs, with req.url I get /personel?username=myuser initially and then only /personel

However in Mozilla Developer tools -> Network, the referer is always http://localhost:31/apiv2/customer/personel?username=myuser

I tried to force the page to render only when the url included the username as a parameter but it does not change anything

PS: Despite what it might look here, jade is correctly intended and not giving any errors.

Answer Source

First, if you have a query param the better way is:

router.get('/personel/:username', function (req, res) {});

Second I think that your page is loaded several times because you have different (but same) routes.

If you use this solution:

router.get('/personel/:username', function (req, res) {});

check the order of your routes. This order does not working:


because sayhello it is catch as :username