Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

set 404 handling via express in node

app.use(function(req, res, next){
  res.status(404);

  // respond with html page
  if (req.accepts('html')) {
    res.render('404', { url: req.url });
    return;
  }

  // respond with json
  if (req.accepts('json')) {
    res.send({ error: 'Not found' });
    return;
  }

  // default to plain-text. send()
  res.type('txt').send('Not found');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: calculate average javascript 
Javascript :: get previous year in javascript 
Javascript :: add checkbox dynamically in javascript 
Javascript :: how to submit form on changed url in function in jquery 
Javascript :: youtube set speed command 
Javascript :: reverse string with recursion 
Javascript :: live vue js port number 
Javascript :: sort in javascript array 
Javascript :: sort arrays according to first array js 
Javascript :: addition of all elements of array in js 
Javascript :: remove selected js 
Javascript :: assign array to another array javascript 
Javascript :: regex usage 
Javascript :: export table data to excel in jquery 
Javascript :: javascript create node from innerhtml 
Javascript :: for each loop with arrowfunction 
Javascript :: how to delete duplicate elements in an array in javascript 
Javascript :: javascript slice vs splice 
Javascript :: dockerfile 
Javascript :: get value of hidden type field 
Javascript :: json load 
Javascript :: django ajax body to json 
Javascript :: custom react native product rating 
Javascript :: node get package.json version 
Javascript :: discord bot javascript 
Javascript :: remove element from array lodash 
Javascript :: javascript split regex new line 
Javascript :: js get all dublicates indexes in array 
Javascript :: javascript emit event 
Javascript :: how to generate a random salt in nodejs 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =