CAMPUS-SAFETY-APP ├── client ├── server ├── .env ├── .gitignore ├── app.js ├──…
- User
CAMPUS-SAFETY-APP ├── client ├── server ├── .env ├── .gitignore ├── app.js ├── campus-safety-fcm-firebase-adminsdk-k3uhg-5fe8524d8f.json ├── package.json ├── README.md └── web.config
This is my current project structure for my node express app and html, css and js frontend.
Usually before i run node app.js, i need to run npm install. But i run npm install in the server directory since the server diretcory also has a package.json file. The reason i added another package.json file to my main directory where app.js is , is for when dploying to azure. So azure tries to run npm install in the main directory which wont work. (azure app service, node app). So what i do is i kinda try and trick azure, so i overide the npm install command to cd into server and then run npm install there, but this doesnt work. whenever i deploy, theres no node modules folder in my server foldetr where dependenices have been installed. i dont know what to do now. Btw , when dploying using github actions to azure, i remove the node_modules folder and rely on azure to install it there on the platforn. cause deploying the node_modules folder takes a really long time. Here's my package.json in the main directory for reference. { "name": "server", "version": "1.0.0", "main": "app.js", "scripts": { "install": "cd server && npm install" }, "keywords": [], "author": "", "license": "ISC", "description": "back-end for campus-safety-app" }
Here is my package.json in the server directory for reference. { "name": "server", "version": "1.0.0", "main": "app.js", "scripts": { "test": "jest", "startApp": "npm i && cd .. && nodemon app.js" }, "keywords": [], "author": "", "license": "ISC", "description": "back-end for campus-safety-app", "devDependencies": { "jest": "^29.7.0", "node-mocks-http": "^1.16.0", "nodemon": "^3.1.4", "supertest": "^7.0.0" }, "dependencies": { "axios": "^1.7.7", "bcryptjs": "^2.4.3", "body-parse": "^0.1.0", "body-parser": "^1.20.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "firebase": "^10.13.0", "firebase-admin": "^12.4.0", "jsonwebtoken": "^9.0.2", "mongodb": "^6.8.0", "mongoose": "^8.5.3", "node-cron": "^3.0.3", "node-fetch": "^3.3.2", "nodemailer": "^6.9.15", "nodemon": "^3.1.4" } }
and finally, the workflow file for reference # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App - campus-safety
on: push: branches: - main workflow_dispatch:
jobs: build: runs-on: ubuntu-latest
steps: - uses: actions/checkout@v4 - name: Set up Node.js version uses: actions/setup-node@v3 with: node-version: "20.x" # Install dependencies - name: Install Node.js dependencies working-directory: ./server run: npm install # Run tests - name: Run tests working-directory: ./server run: npm test continue-on-error: true # Continue even if tests have non-zero exit code # Delete node_modules after tests - name: Clean up node_modules folder working-directory: ./server run: rm -rf node_modules # Zip artifact for deployment - name: Zip artifact for deployment run: zip release.zip ./* -r - name: Upload artifact for deployment job uses: actions/upload-artifact@v4 with: name: node-app path: release.zip - Assistant