Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| kb_it:nodejs [2022/04/14 17:02] – befe | kb_it:nodejs [2022/11/19 16:31] (Version actuelle) – befe | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| ===== npm ===== | ===== npm ===== | ||
| + | |||
| + | ==== Initialisation d'un projet express.js ==== | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | <code bash> | ||
| + | yarn init -y | ||
| + | yarn add -D eslint @types/node @types/ | ||
| + | mkdir src | ||
| + | touch src/app.ts | ||
| + | </ | ||
| + | |||
| + | src/app.ts : | ||
| + | <code javascript> | ||
| + | import express from ' | ||
| + | const app = express(); | ||
| + | const port = 3000; | ||
| + | app.use(express.json()); | ||
| + | app.use(express.static(" | ||
| + | app.set(" | ||
| + | |||
| + | app.get('/', | ||
| + | res.send(' | ||
| + | }); | ||
| + | |||
| + | app.listen(port, | ||
| + | return console.log(`http:// | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | touch tsconfig.json | ||
| + | </ | ||
| + | |||
| + | tsconfig.json : | ||
| + | <code json> | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | ] | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | yarn eslint --init | ||
| + | </ | ||
| + | |||
| + | package.json : | ||
| + | <code json> | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | yarn start | ||
| + | </ | ||
| ==== Commandes utiles ==== | ==== Commandes utiles ==== | ||