A simple Shop API
- Node.js - a JavaScript runtime environment for building and running server-side web applications
- Express.js - a web application framework for Node.js
- Mongodb - a NoSQL database
- OpenAPI 3.0 - an API description format for REST APIs
You need to install:
Upgrade npm to the latest version:
npm install npm@latest -gClone the repository and open project directory
git clone https://github.com/AriaRahmati/shop-api.git
cd shop-apiInstall dependencies and run build command
npm install
npm run buildCreate .env file
To run this project, you will need to add the following environment variables to your .env file.
PORT = 'SERVER_PORT' # Default: 3000
DATABASE_URI = 'YOUR_MONGODB_URI'
JWT_SECRET = 'YOUR_JWT_SECRET'
JWT_LIFETIME = 'PREFERRED_JWT_LIFETIME' # Example: '60', '120ms', '2 days', '10h', '7d'
npm startnpm run devConsole output should look like this:
connecting to database...
connected to database successfully
server is listening on port {PORT}Then you can see the docs at http://localhost:{PORT}/api/v1/docs
and start working with the api at http://localhost:{PORT}/api/v1
Based on commitlint documents:
npx husky installnpx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'See Conventional Commits for more info.
| Type | Description |
|---|---|
| feat | A new feature |
| fix | A bug fix |
| docs | Documentation only changes |
| style | Changes that do not affect the meaning of the code (white-space, formatting etc) |
| refactor | A code change that neither fixes a bug nor adds a feature |
| perf | A code change that improves performance |
| test | Adding missing tests or correcting existing tests |
| build | Changes that affect the build system or external dependencies |
| ci | Changes to our CI configuration files and scripts |
| chore | Other changes that don't modify src or test files |
| revert | Reverts a previous commit |
Shop API uses module-alias to make it easier to work with complex directory structures.
In order to make your intellisense to function, you need to add these paths to compilerOptions in jsconfig.json.
{
"compilerOptions": {
"baseUrl": "./",
"module": "CommonJS",
"target": "ESNext",
"paths": {
"@root/*": ["*"],
"@src/*": ["src/*"],
"@routes/*": ["src/routes/*"],
"@configs/*": ["configs/*"],
"@middlewares/*": ["src/http/middlewares/*"],
"@controllers/*": ["src/http/controllers/*"],
"@validators/*": ["src/http/validators/*"],
"@models/*": ["src/models/*"],
"@errors/*": ["src/errors/*"]
}
}
}