Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Basic Routing Express.js

app.get('/', function (req, res) {
  res.send('Hello World!')
})
Comment

Express Routers

const birds = require('./birds')

// ...

app.use('/birds', birds)
Comment

nodejs express routing get

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

// Connecting with database
const db = mysql.createConnection({
  host: 'localhost',					// The host you're using
  user: 'yourusername',					// The username you use to enter database
  password: 'yourpassword'				// Your password to your username
});

db.connect((error) => {
  if(error) {
    throw error;
  }
  console.log('MySQL Connected');
});

const app = express();

app.get('yourroute', (request, response) => {
  let sql = 'SELECT * FROM yourtable';
  let query = db.query(sql, (error, result) => {
    if(error) {
      throw error;
    }
    console.log(result)					// Use the result you get back here
  })
});

app.listen('3000', () => {
  console.log('Server is listening on port 3000');
});

Comment

express routing

app.get('/example/b', function (req, res, next) {
  console.log('the response will be sent by the next function ...')
  next()
}, function (req, res) {
  res.send('Hello from B!')
})
Comment

Express Router

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

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

module.exports = router
Comment

express basic routing syntax

app.METHOD(PATH, HANDLER)
Comment

express Router()

express.Router( [options] )
Comment

PREVIOUS NEXT
Code Example
Javascript :: find leap year javascript 
Javascript :: firebase hosting rewrite function You need to enable JavaScript to run this app. 
Javascript :: menu with dynamic submenu in javascript 
Javascript :: convert .js file to ts 
Javascript :: clear timers nodejs 
Javascript :: onScrollBottom 
Javascript :: pageSize useEffect 
Javascript :: count repeated characters in a string in react 
Javascript :: set timeout with no name 
Javascript :: remove a key/value mongo 
Javascript :: add decimal places to number javascript 
Javascript :: Get the max value from array - divi modules 
Javascript :: traversing 2d array javascript 
Javascript :: copy multi cell value from one sheet to another using google app script 
Javascript :: html5 javascript json vertical colom grap 
Javascript :: javascript reduce form object 
Javascript :: Nyadorera 
Javascript :: javascript How to show array content in output window 
Javascript :: count object based on status and shop using javascript 
Javascript :: AngularJS two different actions in ng-submit 
Javascript :: object Promise showing instead of data pulled from API call 
Javascript :: EXPO useEffect not called on navigating to same screen 
Javascript :: wrapping a span tag with an a tag with a href target same as the text of the span 
Javascript :: track call recording in facebook using elements 
Javascript :: p5 filter 
Javascript :: Third Example of Event Delegation In JavaScript 
Javascript :: word array to string cryptojs 
Javascript :: javascript object access time complexity 
Javascript :: how to get content disposition from header jquery 
Javascript :: Javascript Area When Base and Height is Known 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =