hallouma875 5 years ago
parent
commit
287bbfd14c
  1. 41
      index.js
  2. 4
      package.json

41
index.js

@ -3,19 +3,52 @@ import fastify from 'fastify';
import axios from 'axios'; import axios from 'axios';
const app = fastify({ logger: true }); const app = fastify({ logger: true });
const URLHOLIDAYS = `https://date.nager.at/api/v2/PublicHolidays/2021/TN`;
const URLCATFACTS= `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`;
const URLFOX = `https://randomfox.ca/floof/`;
const getCatFacts = async () => {
try{
const response = await axios.get(URLANIMALS);
const json = await response.data.map(cats=>cats.text);
return json;
}catch(err){
console.log(err);
return null;
}
};
const getFox = async()=>{
try{
const response = await axios.get(URLFOX);
const json = await response.data.image;
return json;
}catch(err){
console.log(err);
return null;
}
}
const getHolidays = async(country)=>{
try{
const response = await axios.get(`${URLHOLIDAYS}${country}`);
const data = await response.data;
return data;
}catch(err){
console.error(err);
return null;
}
}
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
return { return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
message: "Welcome to your projet"
}; };
}); });
// Run the server! // Run the server!
const start = async () => { const start = async () => {
try { try {
await app.listen(5000);
await app.listen(8090);
} catch (err) { } catch (err) {
app.log.error(err); app.log.error(err);
process.exit(1); process.exit(1);

4
package.json

@ -21,12 +21,12 @@
"pretty-quick": "3.1.0" "pretty-quick": "3.1.0"
}, },
"scripts": { "scripts": {
"start": "nodemon exec babel-node index.js",
"start": "node --experimental-modules index.js ",
"format:write": "prettier --write \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"", "format:write": "prettier --write \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"",
"format:check": "prettier --list-different \"**/*.{js,vue,json,ts,tsx,md,yml,html}\"" "format:check": "prettier --list-different \"**/*.{js,vue,json,ts,tsx,md,yml,html}\""
}, },
"engines": { "engines": {
"node": ">=14"
"node": "12.16.1"
}, },
"type": "module", "type": "module",
"husky": { "husky": {

Loading…
Cancel
Save