Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Nodejs routes

const express = require('express')
const router = express.Router()

const  { 
    getProducts,
    getProduct,
    createProduct,
    updateProduct,
    deleteProduct 
} = require('../controllers/products.js')

router.get('/', getProducts)

router.get('/:productID', getProduct)

router.post('/', createProduct) 

router.put('/:productID', updateProduct) 

router.delete('/:productID', deleteProduct)

module.exports = router
Comment

router NodeJS

const express = require('express');
const router = express.Router();

// Get to home controller req and res function
router.get('/', app.home);
//---- Inside controller.js
const home = (req, res) => {
  res.setHeader('Cache-Control', 'no-cache');
  res.status(200).json({
    status: 'Ok'
  });
};
//----


// NOT FOUND Middleware
router.use((req, res) => {
  res.status(404).json('not found');
});

module.exports = router;
Comment

PREVIOUS NEXT
Code Example
Javascript :: random code generator 
Javascript :: sequelize change column 
Javascript :: angular list contains property 
Javascript :: how to set the development mode in webpack 
Javascript :: react leaflet recenter map 
Javascript :: getdisplaymedia screenshot 
Javascript :: javascript edit form value 
Javascript :: typescript express next middleware type 
Javascript :: vue scroll div to bottom 
Javascript :: react render after data loaded 
Javascript :: How to access the GET parameters after “?” in Express 
Javascript :: discord chatbot 
Javascript :: remove undefined from object js 
Javascript :: how to return a factorial in javascript 
Javascript :: check Browser version js 
Javascript :: merge 2 json objects js 
Javascript :: react usereducer 
Javascript :: reset page js 
Javascript :: using async function in useeffect 
Javascript :: use setstate in function component 
Javascript :: multiply arrays javascript 
Javascript :: storing an image file into buffer field with mongoose 
Javascript :: jquery wait for function to finish 
Javascript :: jquery get all inputs in form 
Javascript :: adding background video angular 6 
Javascript :: javascript switch assignment 
Javascript :: fahrenheit to celsius in javascript 
Javascript :: strpos in javascript 
Javascript :: create select option using jquery 
Javascript :: node -r dotenv/config 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =