-
-
Save mdanshin/8541c87e7d429ddc7a5e5eedb224afc4 to your computer and use it in GitHub Desktop.
MERN server template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a simple MERN server template | |
mkdir mern-server-template | |
cd mern-server-template | |
mkdir server | |
cd server | |
mkdir controllers | |
mkdir router | |
mkdir services | |
mkdir models | |
npm init -y | |
npm install express mongodb mongoose dotenv cors cookie-parser jsonwebtoken bcrypt uuid nodemailer | |
npm install nodemon --save-dev | |
|---/mern-server-template/ | |
| |---controller/ | |
| | |---user-controller.js | |
| |---models/ | |
| | |---users.js | |
| |---router/ | |
| | |---router.js | |
| |---service/ | |
| | |xxx.js | |
| |---.env | |
| |---index.js | |
| |---package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const express = require('express'); | |
const router = require('./routes/routes') | |
const app = express(); | |
const PORT = process.env.PORT || 5000 | |
app.use('/api', router) | |
const start = async () => { | |
try { | |
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}`)); | |
} catch (e) { | |
console.log(e) | |
} | |
} | |
start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mern-server-template", | |
"version": "1.0.0", | |
"description": "MERN Server Template", | |
"main": "index.js", | |
"scripts": { | |
"dev": "nodemon index.js" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/mdanshin/mern-server-template.git" | |
}, | |
"keywords": [ | |
"node", | |
"nodejs", | |
"mern", | |
"server", | |
"template" | |
], | |
"author": "Mikhail Danshin <mdanshin@gmail.com>", | |
"license": "MIT", | |
"bugs": { | |
"url": "https://github.com/mdanshin/mern-server-template/issues" | |
}, | |
"homepage": "https://github.com/mdanshin/mern-server-template#readme" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Router } = require('express') | |
const userController = require('../controllers/user-controller') | |
const router = Router() | |
router.get('/registration', userController.registration) | |
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserController { | |
async registration(req, res, next) { | |
try { | |
res.json({"message": 'OK'}) | |
} catch (e) { | |
} | |
} | |
} | |
module.exports = new UserController(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment