nycdanie
nycdanie

Reputation: 2941

Express route passing in javascript method and not just objects

Is it possible to pass in methods instead of just objects in an Express route?

For example, after redirecting to a specific route, I want to execute an alert function.

app.get(res.redirect('/', function(req, res){
   alert('this is an alert');
   });
);

console.log - seems to be ok, but other methods are not.

I have tried:

res.redirect('/');
alert('this is an alert');

same thing error: ReferenceError: alert is not defined

As, answered below that Alert is a Client side function and not a server side function:

Is there a way that I can tell the server side to pass some client side function after redirecting?

Upvotes: 0

Views: 333

Answers (1)

PedroPovedaQ
PedroPovedaQ

Reputation: 97

The reason this doesn't work is because node.js and express are on the server side. The alert function has to be executed from the browser as it is a property of browser window objects.

See Node.js Alert Causes Crash

Upvotes: 4

Related Questions