A simple URL shortener service built with Node.js and SQLite. This service allows users to shorten long URLs. It's still a work in progress so its going to have more features in the future.
- Shorten long URLs
- Redirect users to the original URL
- Display the created shortened URL
- Basic error handling
- SQLite3 database for storing URLs and users
- Node.js (v14 or higher)
- npm (v6 or higher)
-
Clone the repository:
git clone https://github.com/felipemdutra/url-shortener-service.git cd url-shortener-service
-
Install the dependencies:
npm install sqlite3 express crypto ejs
-
Start the server:
npm run devStart
configured in package.json as:
"scripts": { "devStart": "nodemon ./src/server.js" }
-
Will be available at
http://localhost:8000
.
-
POST /shorten
Create a shortened URL.
-
Request Body:
{ "originalUrl": "https://example.com" }
-
Response:
{ "shortUrl": "http://localhost:8000/abcdef" }
-
-
GET /:shortUrl
Redirect to the original URL.
The service uses SQLite3 to store the URLs. The database schema includes a table urls
, and a table users
, with the following columns:
id
(INTEGER): Primary keyoriginalUrl
(TEXT): The original long URLshortUrl
(TEXT): The shortened URL
id
(INTEGER): Primary keyusername
(TEXT): User's usernameemail
(TEXT): User's emailpassword
(TEXT): User's password ( We hash the password before inserting into the database)
./src/server.js
: Entry point of the application./src/routes/
: Handles requests and routes./src/controllers/
: All the logic behind requests
Contributions are welcome! Please open an issue or submit a pull request.