npm install -g typescript-express-generator
ts-express --view=ejs server
cd server
npm install
dist
資料夾的功能:dist 資料夾用來儲存你的項目經過編譯和打包後的文件。這些文件是最終準備部署到伺服器或者提供給用戶的版本,已經優化並且壓縮過了,不再包含原始的開發檔案。簡單來說,dist 資料夾就是程式碼的最終成果,可以直接部署和運行。
npm run build
cd server
"scripts": {
"start": "set NODE_OPTIONS=--trace-deprecation --abort-on-uncaught-exception && set NODE_ENV=development && nodemon --exec ts-node ./bin/www.ts",
"build": "sh etc/build.sh"
}
const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
//改成
const port = normalizePort(process.env.PORT || '30000');
app.set('port', port);
npm run start
mkdir my-ts-server
cd my-ts-server
npm init -y
services:
mysql:
image: mysql:5.7
container_name: mysql
platform: linux/x86_64
ports:
- "3306:3306"
volumes:
- mysql-data-volumes:/var/lib/mysql
- ./mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
restart: always
environment:
MYSQL_USER: xuemi
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
volumes:
mysql-data-volumes:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
#bind-address = 127.0.0.1
symbolic-links=0
secure-file-priv = ""
npm install typescript @types/node @types/express ts-node-dev --save-dev
安裝了這些套件的功能:
npm install -g typescript-express-generator
ts-express --view=ejs server
在 package.json
中添加啟動腳本:
"scripts": {
"start": "set NODE_OPTIONS=--trace-deprecation --abort-on-uncaught-exception && set NODE_ENV=development && nodemon --exec ts-node ./bin/www.ts",
"build": "sh etc/build.sh"
}
docker-compose up -d
npm run start