|
1 | | -const fs = require('fs'); |
| 1 | +import fs from 'fs'; |
2 | 2 |
|
3 | 3 | const filePath = './src/backend/.env'; |
4 | 4 | const lineToAdd = 'DATABASE_URL="postgresql://postgres:docker@localhost:5432/nerpm?schema=public"'; |
5 | 5 |
|
6 | 6 | if (!fs.existsSync(filePath)) { |
7 | | - fs.writeFileSync(filePath, lineToAdd, 'utf8'); |
8 | | - return; |
| 7 | + fs.writeFileSync(filePath, lineToAdd, 'utf8'); |
| 8 | + return; |
9 | 9 | } |
10 | 10 |
|
11 | 11 | fs.readFile(filePath, 'utf8', (err, data) => { |
12 | | - if (err) { |
13 | | - console.error('Error reading file:', err); |
14 | | - return; |
15 | | - } |
| 12 | + if (err) { |
| 13 | + console.error('Error reading file:', err); |
| 14 | + return; |
| 15 | + } |
16 | 16 |
|
17 | | - // Split file contents into lines |
18 | | - const lines = data.trim().split('\n'); |
| 17 | + // Split file contents into lines |
| 18 | + const lines = data.trim().split('\n'); |
19 | 19 |
|
20 | | - for (const line of lines) { |
21 | | - //db url already exists, no need to add it |
22 | | - if (line.startsWith("DATABASE_URL=")) return; |
23 | | - } |
| 20 | + for (const line of lines) { |
| 21 | + //db url already exists, no need to add it |
| 22 | + if (line.startsWith('DATABASE_URL=')) return; |
| 23 | + } |
24 | 24 |
|
25 | | - fs.appendFile(filePath, `\n${lineToAdd}`, 'utf8', (err) => { |
26 | | - if (err) { |
27 | | - console.error('Error appending line to file:', err); |
28 | | - return; |
29 | | - } |
30 | | - }); |
| 25 | + fs.appendFile(filePath, `\n${lineToAdd}`, 'utf8', (err) => { |
| 26 | + if (err) { |
| 27 | + console.error('Error appending line to file:', err); |
| 28 | + return; |
| 29 | + } |
| 30 | + }); |
31 | 31 | }); |
0 commit comments