A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
Előző változat mindkét oldalon Előző változat Következő változat | Előző változat | ||
oktatas:web:nodejs:npm_projekt [2021/10/16 09:47] admin [Csak npm] |
oktatas:web:nodejs:npm_projekt [2021/10/20 22:11] admin eltávolítva |
||
---|---|---|---|
Sor 111: | Sor 111: | ||
- | ===== Express projekt ===== | ||
- | |||
- | <code> | ||
- | mkdir projekt01 | ||
- | cd projekt01 | ||
- | npm init | ||
- | </code> | ||
- | |||
- | Az npm init lehetséges kimenete: | ||
- | <code> | ||
- | $ npm init | ||
- | This utility will walk you through creating a package.json file. | ||
- | It only covers the most common items, and tries to guess sensible defaults. | ||
- | |||
- | See `npm help json` for definitive documentation on these fields | ||
- | and exactly what they do. | ||
- | |||
- | Use `npm install <pkg>` afterwards to install a package and | ||
- | save it as a dependency in the package.json file. | ||
- | |||
- | Press ^C at any time to quit. | ||
- | package name: (projekt01) | ||
- | version: (1.0.0) | ||
- | description: teszt | ||
- | entry point: (index.js) | ||
- | test command: | ||
- | git repository: | ||
- | keywords: | ||
- | author: Nagy János | ||
- | license: (ISC) MIT | ||
- | About to write to /home/janos/projekt01/package.json: | ||
- | |||
- | { | ||
- | "name": "projekt01", | ||
- | "version": "1.0.0", | ||
- | "description": "teszt", | ||
- | "main": "index.js", | ||
- | "scripts": { | ||
- | "test": "echo \"Error: no test specified\" && exit 1" | ||
- | }, | ||
- | "author": "Nagy János", | ||
- | "license": "MIT" | ||
- | } | ||
- | |||
- | |||
- | Is this OK? (yes) yes | ||
- | </code> | ||
- | |||
- | |||
- | Telepítsük az express csomagot: | ||
- | npm install express | ||
- | |||
- | Lehetséges kimenet: | ||
- | <code> | ||
- | npm install express | ||
- | npm notice created a lockfile as package-lock.json. You should commit this file. | ||
- | npm WARN projekt01@1.0.0 No repository field. | ||
- | |||
- | + express@4.16.4 | ||
- | added 48 packages from 36 contributors and audited 121 packages in 3.732s | ||
- | found 0 vulnerabilities | ||
- | </code> | ||
- | |||
- | |||
- | Írjuk meg a programunkat: | ||
- | <code javascript index.js> | ||
- | const express = require('express') | ||
- | const app = express(); | ||
- | |||
- | app.get('/', (req, res) => { | ||
- | res.send('Helló Világ!') | ||
- | }); | ||
- | |||
- | app.listen(8000, () => { | ||
- | console.log('Példa alkalmazás port 8000') | ||
- | }); | ||
- | </code> | ||
- | |||
- | |||
- | <code> | ||
- | $ node index.js | ||
- | Példa alkalmazás port 8000 | ||
- | </code> | ||
- | |||
- | |||
- | |||
- | Böngészőbe írjuk be: | ||
- | http://192.168.5.100:8000/ | ||
===== package-lock.json ===== | ===== package-lock.json ===== |