Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Basic Routing Express.js

app.get('/', function (req, res) {
  res.send('Hello World!')
})
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 basic routing syntax

app.METHOD(PATH, HANDLER)
Comment

PREVIOUS NEXT
Code Example
Javascript :: nginx location regex * 
Javascript :: Routes & GET Requests 
Javascript :: JavaScript finally() method 
Javascript :: change size of font awesome icon react 
Javascript :: javascript null 
Javascript :: background image react 
Javascript :: javascript find textarea 
Javascript :: vuetify select array 
Javascript :: what is a node 
Javascript :: react hooks useeffect 
Javascript :: loadsh debounce 
Javascript :: . is not recognized as an internal command npm run 
Javascript :: react datetime mannual editing 
Javascript :: Drop it 
Javascript :: calculate init code hash nodejs 
Javascript :: javascript get data from hashmap 
Javascript :: get table schema with knex 
Javascript :: jest visit a page 
Javascript :: sort datatable c# 
Javascript :: tskill nodejs port 
Javascript :: jquery to javascript converter online 
Javascript :: Run a second function only after the first function is completely finished 
Javascript :: eeeeee 
Javascript :: check if item is already registered in angular angularfire site:stackoverflow.com 
Javascript :: what is a 0 based language 
Javascript :: javascript get browser is electron 
Javascript :: 300000/12 
Javascript :: change windlow location relitave to current one 
Javascript :: complex type in javascript and memory allocation 
Javascript :: program to parenthesize an expression 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =