This is a Node.js application using Express, Sequelize, and PostgreSQL. It provides a REST API with authentication and other functionalities.
- Node.js (v14 or higher)
- npm (v6 or higher)
- PostgreSQL
-
Clone the repository:
git clone https://github.com/yourusername/yourrepository.git cd yourrepository
-
Install dependencies:
npm install
-
Set up PostgreSQL:
- Install PostgreSQL:
sudo apt update sudo apt install postgresql postgresql-contrib
- Start PostgreSQL service:
sudo systemctl start postgresql sudo systemctl enable postgresql
- Switch to the
postgres
user and open the PostgreSQL prompt:sudo -i -u postgres psql
- Create a new database and user:
CREATE DATABASE mydatabase; CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword'; GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
- Exit the PostgreSQL prompt:
\q exit
- Install PostgreSQL:
-
Configure environment variables:
- Create a
.env
file in the root directory of your project and add the following:OPENAI_API_KEY=asd PORT=8080 ASSISTANT_ID=asst_asd LEYES_SALTA_VS_ID=vs_asd PROJECT_NAME=group_ai_salta_backend SERVER_URL=http://localhost FRONTEND_URL=http://localhost:5173 # JWT AND CERTS JWT_SECRET=asd JWT_REFRESH_SECRET=asd KEY_PATH=~/certs/key.pem CERT_PATH=~/certs/cert.pem # Paths DOWNLOADS_PATH=~/downloads UPLOADS_PATH=~/uploads # Database DB_NAME=group_ai_salta DB_USER=root DB_PASSWORD=admin123 DB_HOST=localhost DB_PORT=5432
- Create a
-
Create necessary directories:
-
Create the
downloads
anduploads
directories:mkdir -p ~/downloads ~/uploads
-
Add the following lines to your
.env
file:DOWNLOADS_PATH=~/downloads UPLOADS_PATH=~/uploads
-
-
Install Flyway CLI:
- Download and extract Flyway CLI:
wget -qO- https://download.red-gate.com/maven/release/com/redgate/flyway/flyway-commandline/10.19.0/flyway-commandline-10.19.0-linux-x64.tar.gz | tar -xvz
- Create a symbolic link to make Flyway accessible from anywhere:
sudo ln -s `pwd`/flyway-10.19.0/flyway /usr/local/bin
- Download and extract Flyway CLI:
-
Run Migrations:
- To run migrations, use the following command:
flyway -configFiles=db/flyway.conf migrate
- or you can use the npm script:
npm run build:migrate
- To run migrations, use the following command:
-
Build and run the application:
npm start
-
Access the application:
- The server will be running on
http://localhost:3000
. - The API endpoints will be available under
/api
and/auth
. (TODO: complete the list)
- The server will be running on
-
Register:
POST /auth/register
{ "username": "testuser", "password": "testpassword" }
-
Login:
POST /auth/login
{ "username": "testuser", "password": "testpassword" }
(TODO: complete the list)
- Example Protected Route:
GET /api/protected-route
- Requires a valid JWT token in the
Authorization
header.
- Requires a valid JWT token in the
This project is licensed under the MIT License.