This Node.js web server built with Express.js handles a data collection of job posting sentences. It provides a simple API for performing CRUD operations on the job postings and includes a translation service integration. The server uses in-memory storage for the job postings.
To set up the project, follow these steps:
- Replace the
.env.sample
file with a new file named.env
. - Configure the following environment variables in the
.env
file:
- PORT: Set the port number you want the server to listen on.
- GOOGLE_APPLICATION_CREDENTIALS: Provide the path to the Firebase credentials file. You need to create a Firebase account and obtain the credentials file to use Firebase services.
- DEEPL_KEY: Add your DeepL API key obtained by creating an account on DeepL.
- JWT_SECRET: Set a secret string for JWT (JSON Web Token) authentication in the application.
Start the project:
npm install
npm run start
The project consists of two main components: the API and scripts.
The API provides a basic CRUD (Create, Read, Update, Delete) functionality for managing job postings. To access the full CRUD operations, you need to generate a JWT token by calling the login endpoint:
e.g
curl --location 'localhost:3000/api/authentication/login' \
--header 'Content-Type: application/json' \
--data '{
"user": "Random Name",
"password": "Random Password"
}'
Include the generated JWT token in the headers for subsequent POST, PUT, and DELETE operations using the "Authorization" header.
Translation service is also integrated into the API. To translate a sentence, you can use the following endpoint:
e.g
curl --location 'localhost:3000/api/sentences/translate/5?lang=NL'
I the root of this project there is a Postman Collection with all the routes.
There are two main scripts included in this project:
-
Firebase Sync: This script synchronizes the data in this repository with a different data structure in Firebase. To run the script, use the following command:
npm run firebase
-
Word Count: This script retrieves the 100 most frequently used words. To run the script, use the following command:
npm run wordCount
Run test's with npm run test
Node.js Version used: 18.16.0