This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
const connection = require("./conf"); | |
app.get("/api/movies", (req, res) => { | |
connection.query("SELECT * from movie", (err, results) => { | |
if (err) { | |
res.status(500).send("Error while recovering movies"); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
app.get(`/api/movies`, (request, response) => { | |
response.send("Récupération de tous les films"); | |
}); | |
app.get(`/api/movies/:id`, (request, response) => { | |
response.json({ id: request.params.id }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const url = require("url"); | |
const port = 8000; | |
const requestHandler = (request, response) => { | |
let parsedUrl = url.parse(request.url, true); | |
if (parsedUrl.query.name && parsedUrl.query.city) { | |
response.end( | |
`Hello, ${parsedUrl.query.name} from ${parsedUrl.query.city}!` | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> INSERT INTO school (name, country, capacity) | |
-> VALUES ('Beauxbatons Academy of Magic', 'France', 550), | |
-> ('Castelobruxo', 'Brazil', 380), | |
-> ('Durmstrang Institute', 'Norway', 570), | |
-> ('Hogwarts School of Witchcraft and Wizardry', 'United Kingdom', 450), | |
-> ('Ilvermorny School of Witchcraft and Wizardry', 'USA', 300), | |
-> ('Koldovstoretz', 'Russia', 125), | |
-> ('Mahoutokoro School of Magic', 'Japan', 800), | |
-> ('Uagadou School of Magic', 'Uganda', 350); | |
Query OK, 8 rows affected (0.02 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Récupère tous les champs pour les sorciers nés entre 1975 et 1985 | |
mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31'; | |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+ | |
| id | firstname | lastname | birthday | birth_place | biography | is_muggle | | |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+ | |
| 1 | harry | potter | 1980-07-31 | london | | 0 | | |
| 2 | hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 | | |
| 4 | ron | weasley | 1980-03-01 | | Best friend of Harry | 0 | | |
| 5 | ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Request with Wilders URL | |
GET https://http-practice.herokuapp.com/wilders | |
### Request with 2 filters : Javascript & page 2 | |
GET https://http-practice.herokuapp.com/wilders?language=JavaScript&page=2 | |
### Request url-encoded | |
POST https://http-practice.herokuapp.com/wilders | |
Content-Type: application/x-www-form-urlencoded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
class MyTimer extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
timer: 0, | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cowsay = require("cowsay"); | |
console.log(cowsay.say({ | |
text : "hello boy", | |
e : "><", | |
T : "U " | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
console.log('Please enter your age') | |
process.stdin.on('data', (age) => { | |
let actualYear = new Date().getFullYear(); | |
if (typeof(parseInt(age)) === "number" && parseInt(age) < 100 && parseInt(age) > 0) { | |
console.log(`Year of your birth : ${actualYear - age}`); | |
process.exit(); | |
} else { | |
console.log("Invalide input, try again !") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
constructor(name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
tellMyName() { | |
console.log(`I am ${this.name}`) | |
} | |
tellMyAge() { | |
console.log(`I am ${this.age} old`) |