This app creates the api's (having the encryption/decryption logic) which will be consumed by FE.
- NodeJS
- Express (to write backend APIs)
- MYSQL Database
- Mocha-Chai for testcases
- clone this app using command [email protected]:SumitJadiya/URL_shortner_node_backend.git.
- run "npm install" to install dependencies.
- Setup Mysql in local and then create a file .env in the main(same directory having readme) folder, this file will have the contents:
- SERVER_PORT = <your_server_port>
- DBHOST = '<your_mysql_db_host>'
- DBUSER = '<your_mysql_db_user>'
- DBPASSWORD = '<your_mysql_db_pass>'
- DBDATABASE = '<your_mysql_db_database>'
- TESTING_URL = '<your_local_url>'+SERVER_PORT
- once the dependencies are installed, and MYSQL setup is complete. You're good to work on this repo.
- Models -> The list of all the models (In our case, the only model is URL)
- Controllers -> The core logic of encryption/decryption
- Routes -> Routes through which FE can access the APIs
- config -> Configuration related file (In our case, MYSQL database connection details)
- test -> Test related files
The longString is encoded to a shortString by generating random characters from a string set. Here, I've used a String (which consists of all the characters, numbers) to generate the random characters.
As soon as the string is encoded, the string is stored in database (MYSQL in this app)
When User tries to encode a longString again and again, I'm checking if the URL is already present i'm returning the short URL as it is without generating new one.