npm i --save express nodemon dotenv sequelize sequelize-cli pg bcrypt body-parser jsonwebtoken express-validator cors
Check here
create .sequelizerc
touch .sequelizerc
past the code below for sequelize init
const path = require('path');
module.exports = {
"config": path.resolve('./config', 'database.js'),
"models-path": path.resolve('models'),
"seeders-path": path.resolve('database', 'seeders'),
"migrations-path": path.resolve('database', 'migrations')
}
initialize sequelize
sequelize init
sequelize model:create --name User --attributes firstName:string,lastName:string,email:string,password:string,gender:string,avatar:string
sequelize db:migrate
sequelize db:migrate:undo
sequelize seed:create --name users
sequelize db:seed:all
sequelize db:seed:undo
sequelize model:create --name Chat --attributes type:string
sequelize model:create --name ChatUser --attributes chatId:integer,userId:integer
sequelize model:create --name Message --attributes type:string,message:text,chatId:integer,fromUserId:integer
- Ubuntu 18.04
- t3-small
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt install nginx
sudo npm install -g sequelize-cli sequelize pg express nodemon dotenv sequelize sequelize-cli pg bcrypt body-parser jsonwebtoken express-validator cors
node -v
npm -v
curl localhost
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm ls-remote --lts
nvm install 12.18.3
sudo apt-get install postgresql postgresql-client
sudo -u postgres psql
\password
\q
psql -U postgres -h localhost
CREATE DATABASE chatapp;
\l
\c chatapp;
CREATE USER tom;
\password tom;
GRANT ALL PRIVILEGES ON DATABASE chatapp TO tom;
psql -U tom -h localhost -d chatapp;
git clone https://github.com/ChenTsungYu/chat-app-backend.git
cd chat-app-backend
sudo vim .env
APP_KEY=YourAppKey
APP_URL=http://YourIP
APP_PORT=3000
DB_HOST=YourDBHost
DB_USER=YourDBUserName
DB_PASSWORD=YourDBPassword
DB_DATABASE=chatApp
:wq!
sudo npm install pm2@latest -g
Start your app using the process manager
pm2 start app.js
sudo vim /etc/nginx/sites-available/chatapp.conf
sudo ln -s /etc/nginx/sites-available/chatapp.conf /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
sudo pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
sudo systemctl enable pm2-root
sudo pm2 save
sudo systemctl start pm2-root
Check the status of pm2-root
sudo systemctl status pm2-root
- 選擇AWS S3 服務,點擊進入目標 Bucket
- 點擊 Permissions,至頁面底部找到 Cross-origin resource sharing (CORS),點擊 Edit
- 貼上下方設定,修改
AllowedOrigins
成 EC2 的網域
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE",
"HEAD"
],
"AllowedOrigins": [
"http://YourEC2Domain"
],
"MaxAgeSeconds": 3000
}
]
- 儲存修改