commit ad0098bc7cf553d04930fd08abaec008395035fa Author: Ben Elferink Date: Mon Dec 21 23:03:50 2020 +0200 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90157b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba6bb37 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# MERN Stack Template + +- **M** = [MongoDB](https://www.mongodb.com) +- **E** = [Express.js](https://expressjs.com) +- **R** = [React.js](https://reactjs.org) +- **N** = [Node.js](https://nodejs.org) + +## Initialize project: + +###### Server (Backend): + +1. Prepare your MongoDB database +2. Terminal: `cd server` +3. Terminal: `npm install` +4. Set your database within `index.js` +5. Terminal: `npm start` +6. Start writing code... + +###### Client (Frontend): + +1. Terminal: `cd client` +2. Terminal: `npm install` +3. Terminal: `npm start` +4. Start writing code... diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..b1b8d4b --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,3 @@ +/node_modules +.DS_Store +.eslintcache \ No newline at end of file diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..cc315a1 --- /dev/null +++ b/client/package.json @@ -0,0 +1,28 @@ +{ + "name": "client", + "version": "0.1.0", + "main": "index.js", + "scripts": { + "start": "react-scripts start" + }, + "author": "Ben Elferink", + "license": "ISC", + "dependencies": { + "axios": "^0.21.0", + "react": "^17.0.1", + "react-dom": "^17.0.1", + "react-scripts": "^4.0.1" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/client/public/index.html b/client/public/index.html new file mode 100644 index 0000000..17aed91 --- /dev/null +++ b/client/public/index.html @@ -0,0 +1,12 @@ + + + + + + MERN_STACK + + + +
+ + diff --git a/client/src/App.js b/client/src/App.js new file mode 100644 index 0000000..c824930 --- /dev/null +++ b/client/src/App.js @@ -0,0 +1,7 @@ +import React from 'react'; + +function App() { + return
Hello World - React.js
; +} + +export default App; diff --git a/client/src/api/index.js b/client/src/api/index.js new file mode 100644 index 0000000..bb413bc --- /dev/null +++ b/client/src/api/index.js @@ -0,0 +1,6 @@ +import axios from 'axios'; + +const url = 'http://localhost:8080/'; + +// export const getSomething = () => axios.get(url + 'path'); +// export const postSometing = (form) => axios.post(url + 'path', form); diff --git a/client/src/index.js b/client/src/index.js new file mode 100644 index 0000000..c1f31c5 --- /dev/null +++ b/client/src/index.js @@ -0,0 +1,10 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +ReactDOM.render( + + + , + document.getElementById('root') +); diff --git a/client/src/style/style.css b/client/src/style/style.css new file mode 100644 index 0000000..591a15b --- /dev/null +++ b/client/src/style/style.css @@ -0,0 +1,9 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: Arial, Helvetica, sans-serif; +} diff --git a/server/.env.example b/server/.env.example new file mode 100644 index 0000000..8a17d5a --- /dev/null +++ b/server/.env.example @@ -0,0 +1 @@ +CONNECTIONS_URL = "URL" \ No newline at end of file diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..e1ce161 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,3 @@ +/node_modules +.DS_Store +.env \ No newline at end of file diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..4825c3c --- /dev/null +++ b/server/index.js @@ -0,0 +1,30 @@ +import mongoose from 'mongoose'; +import express from 'express'; +import dotenv from 'dotenv'; +import cors from 'cors'; + +// initialize app +const app = express(); +dotenv.config(); + +// connect to db ---> if you want to connect to cloud server: edit "CONNECTION_URL" in -> .env file +const DB_NAME = 'testDB'; // if you want to use local server: edit this "DB_NAME" (and remove the "CONNECTION_URL" from -> .env file) +const CONNECTION_URL = process.env.CONNECTION_URL || `mongodb://localhost:27017/${DB_NAME}`; +const PORT = process.env.PORT || 8080; // 8080 === development port +const DEPRECATED_FIX = { useNewUrlParser: true, useUnifiedTopology: true }; // change this with (possible) warnings on first connection + +mongoose + .connect(CONNECTION_URL, DEPRECATED_FIX) + .then(() => console.log('✅ MongoDB connected')) + .then(() => app.listen(PORT, () => console.log(`✅ Listening on port: ${PORT}`))) + .catch((error) => console.log(`❌ ${error}`)); + +mongoose.connection.on('error', (err) => console.log(`❌ MongoDB: ${err}`)); + +// middlewares +app.use(express.json()); // body parser +app.use(cors()); // enables requests + +// routes +app.get('/', (req, res) => res.send('Hello World - Express.js')); +// app.use('/', IMPORTED_ROUTES); diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..f9224e7 --- /dev/null +++ b/server/package.json @@ -0,0 +1,18 @@ +{ + "name": "server", + "version": "0.1.0", + "main": "index.js", + "type": "module", + "scripts": { + "start": "nodemon index.js" + }, + "author": "Ben Elferink", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "express": "^4.17.1", + "mongoose": "^5.11.8", + "nodemon": "^2.0.6" + } +}