-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (43 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env node
const fs = require("fs");
const path = require("path");
const express = require("express");
const app = express();
const dir = process.cwd();
const modelsDir = path.join(dir, "models");
const viewsDir = path.join(dir, "views");
const controllersDir = path.join(dir, "controllers");
const assetsDir = path.join(dir, "assets");
const serverFile = path.join(dir, "server.js");
if (!fs.existsSync(modelsDir)) {
fs.mkdirSync(modelsDir);
}
if (!fs.existsSync(routesDir)) {
fs.mkdirSync(routesDir);
}
if (!fs.existsSync(viewsDir)) {
fs.mkdirSync(viewsDir);
}
if (!fs.existsSync(assetsDir)) {
fs.mkdirSync(assetsDir);
}
if (!fs.existsSync(controllersDir)) {
fs.mkdirSync(controllersDir);
}
if (!fs.existsSync(serverFile)) {
fs.writeFileSync(serverFile, `const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Your root endpoint running successfully');
});
app.get('/profile', (req, res)=>{
res.send('Here is your profile page!');
})
app.listen(3000, () => {
console.log('Server listening on port 3000');
});
`);
console.log("Express MVC structure created successfully!");
}else{
console.log('Express MVC Directory Structure already exists !');
}