Internship Project / Exam Project 1 at Noroff
Node.js v23.5.0 should also work on v22.12.0 (with Long Term Support)
MySQL Workbench or similar Database Management System
-
git clone https://github.com/donnybrilliant/merchandizer.git cd merchandizer -
Ensure that Node.js is installed on your machine, then run the following command to install the required packages:
npm install
-
To create the database needed for this application, run the following SQL command in your DBMS (f.x MySQLWorkbench):
CREATE DATABASE merchandizer;
-
Create a new MySQL user 'admin' with the password 'P@ssw0rd'
-
Grant all privileges on the 'myTodo' database to 'admin'
-
Apply the privilege changes
In your DBMS, run this SQL command:
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'P@ssw0rd';
GRANT ALL PRIVILEGES ON merchandizer.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;-
This project requires certain environment variables to be set in a
.envfile. Please copy or rename the env-example file to.envbefore running the application.mv .env-example .env
The appropriate values should already be set, except the token, which you need to create:
-
Open you terminal and start node:
node -
Type
require('crypto').randomBytes(64).toString('hex') -
Copy the token to .env where it says
TOKEN_SECRET=ADMIN_USERNAME: The username for the adminADMIN_PASSWORD: The password for the adminDATABASE_NAME: The name of the databaseDATABASE_PORT: The port of the databaseDIALECT: The database dialect to usePORT: The port on which the application will runHOST: The host for the database connectionTOKEN_SECRET: A secret key used for signing JWT tokensAWS_ACCESS_KEY_ID: Your AWS access key ID, which is used to authenticate requests to AWS servicesAWS_SECRET_ACCESS_KEY: Your AWS secret access key, which is used with the access key ID to sign requestsAWS_S3_BUCKET_NAME: The name of the S3 bucket where your application will store and retrieve filesAWS_REGION: The AWS region where your S3 bucket is located
For testing image uploading for product images and user avatars, set up your own AWS S3 Bucket. Login here and follow this guide
This might be easier to test if you change the
base_urlcollection variable in the Postman Collection tohttps://merchandizer.onrender.comand test it on the deployed production environment.
-
Start the application using the following command:
npm start
The application will be accessible at to use with at localhost:3000
-
This can be done before or after starting the application and should not affect the data in the database
npm run test
The Merchandizer API is designed to manage band merchandise inventory during tours. For detailed examples and responses, refer to the Postman Collection
If you want to populate the database with example data for manual testing, this can be done with a POST request to the endpoint [localhost:3000/init]. This also adds the admin user specified in the Course Assignment Instructions. This is not available in the production deployment since you dont need to be authenticated to use this endpoint.
- express: Web application framework for building the server and routes.
- sequelize: ORM for managing SQL databases.
- mysql2: Modern MySQL client.
- dotenv: Loads environment variables from .env file.
- jsonwebtoken: Used for securing routes via token authentication.
- swagger-ui-express: Serves Swagger UI for API documentation.
- morgan: Logs HTTP requests to the console.
- debug: Creates debug logs.
- http-errors: Creates HTTP errors for error handling.
- @aws-sdk/client-s3: AWS SDK for JavaScript S3 client.
- express-validator: Middleware for validating and sanitizing user input.
- multer: Middleware for handling multipart/form-data, used for uploading files.
- sharp: High-performance image processing library.
- jest: Used for writing and running tests.
- supertest: Provides a high-level abstraction for testing HTTP servers.
sequelize
express-validator
multer
sharp
Promise.all
setting up S3 Bucket
AWS-SDK
AWS-SDK@Client-S3
API Best Practices
router.param
Postman to Swagger
ChatGPT