Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

express router file

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

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now());
  next();
});
// define the home page route
router.get('/', function (req, res) {
  res.send('Birds home page');
});
// define the about route
router.get('/about', function (req, res) {
  res.send('About birds');
});

module.exports = router;
Comment

nodejs: router by use express and path package

// use Express 
// use Path

const express = require('express');
const path = require('path');

const app = express();


// ###Create Public folder
app.use(express.static('./public'));




app.get('/', (req, res) => {
    res.sendFile(path.resolve(__dirname, './navbar-app/index.html'));
});


app.all('*', (req, res) => {
    res.status(404).send('Resource not founded');
})


app.listen(5000, () => {
    console.log('Server is listening on PORT: 5000');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: stop a site from reloading javascript 
Javascript :: javascript extract date from string 
Javascript :: javascript document.createElement add function 
Javascript :: iterate array in javascrpt 
Javascript :: kebab case javascript 
Javascript :: Find the maximum number in a jagged array of numbers 
Javascript :: javascript get array difference 
Javascript :: javascript format date mm/dd/yyyy 
Javascript :: javascript onclick button 
Javascript :: tick.json code 
Javascript :: error metro bundler process exited with code 1 react native 
Javascript :: vue.js 
Javascript :: this setstate previous state react 
Javascript :: preg_match javascript 
Javascript :: jquery get 2nd child 
Javascript :: sequelize change column 
Javascript :: html2pdf example angular 
Javascript :: typescript express next middleware type 
Javascript :: react render after fetch 
Javascript :: how to rotate an array in javascript 
Javascript :: mongoose put request 
Javascript :: poll in javascript 
Javascript :: default Electron icon is used reason=application icon is not set 
Javascript :: leaflet circle get bounds 
Javascript :: assign array to another array javascript 
Javascript :: react webpack.config.js example 
Javascript :: is jwt token expired 
Javascript :: leap year function javascript 
Javascript :: create an element jquery 
Javascript :: spotify web player 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =