Build Automation & CI Pipeline
1. Install Node.js
Download dan install Node.js dulu: Node.js Official Website
2. Buat Folder Project
Buka:
- CMD
lalu ketik dibawah ini:
mkdir tugas-devopsmasuk ke folder:
cd tugas-devops3. Inisialisasi Project Node.js
npm init -yNanti otomatis akan membuat file: package.json
4. Install Express.js
npm install express5. Install Dev Dependencies
npm install --save-dev nodemon eslint jest supertestBuat File Server
1. Buat file index.js
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello DevOps");
});
app.listen(3000, () => {
console.log("Server berjalan di port 3000");
});2. Setup npm Scripts
Buka file:
package.jsonCari bagian:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}Ubah jadi:
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js",
"build": "echo Build Success",
"test": "jest",
"lint": "eslint ."
}Jalankan Nodemon:
npm.cmd run dev3. Setup ESLint
Get musa okta’s stories in your inbox
Join Medium for free to get updates from this writer.
ketik:
npx.cmd eslint --initTEST LOKAL
1. Jalankan ESLint
npm.cmd run lint2. Buat Folder test
3. Buat File app.test.js
Klik kanan folder test -> new file
4. Isi app.test.js
const request = require("supertest");
const app = require("../index");
describe("GET /", () => {
it("should return Hello DevOps", async () => {
const res = await request(app).get("/");
expect(res.statusCode).toBe(200);
expect(res.text).toBe("Hello DevOps");
});
});5. Ubah isi index.js
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello DevOps");
});
if (require.main === module) {
app.listen(3000, () => {
console.log("Server berjalan di port 3000");
});
}
module.exports = app;6. Jalankan Test
npm.cmd testPUSH KE GITHUB
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/Musakings/tugas-devops.git
git branch -M main
git push -u origin mainHasil
GitHub Actions
Link GitHub : https://github.com/Musakings/tugas-devops








