I. Cài đặt Project
1. Cài NodeJS và npm
- Download và cài đặt: https://nodejs.org/en/download/
- Kiểm tra version bằng terminal của VSCode
node -v
npm -v
2. Tạo Project
- Tạo thư mục: VD: D:\Projects\medihome
- Dùng VSCode mở thư mục project lên, và cài npm
npm init
- Cài thư viện Express
npm install express
II. Hello wold
1. Tạo file ./src/server.js
1 2 3 4 5 6 7 8 9 10 |
const express = require('express'); const app = express(); const port = process.env.PORT || 3000; app.get('/', (req, res) => { res.send('Hello World!'); }) app.listen(port, () => { console.log(`Example app listening at http://localhost:` + port); }) |
2. Sửa file ./package.json
1 |
"main": "src/server.js", |
3. Khởi chạy
- Dùng terminal:
node src/server.js
- Dùng trình duyệt vào link: http://localhost:3000/