项目作者: Daniel-Knights

项目描述 :
A MEVN boilerplate setup with example CRUD, auth/user, email, validation, lazyload and pagination functionality out of the box.
高级语言: JavaScript
项目地址: git://github.com/Daniel-Knights/MEVN-Boilerplate.git
创建时间: 2020-05-24T16:33:22Z
项目社区:https://github.com/Daniel-Knights/MEVN-Boilerplate

开源协议:

下载


MEVN Boilerplate

A MEVN boilerplate setup with:


  • Example CRUD functionality

  • Auth/user functionality

  • Lazy-loaded photos

  • Email

  • Validation

  • Pagination

Includes Heroku deployment walkthrough.

Requires manually setting up a MongoDB database.

Demo

From boilerplate

  1. npm i -g nodemon
  2. nodemon
  3. cd client
  4. npm i
  5. npm run serve

Create a .env file in your root directory and add:

  1. MONGO_URI=<your-mongodb-connection-string>
  2. JWT_SECRET=<hex_string_from_server.js_function>
  3. EMAIL_ACCOUNT=<your-gmail-account>
  4. EMAIL_PASSWORD=<your-google-app-password>
  5. PORT=3000

Create a .env file in the client directory and add:

  1. VUE_APP_NODE_ENV=development

In server/routes/api/auth.js and server/routes/api/posts.js, inside the collection functions, replace “vue_express” with your database name:

  1. return connection.db('vue_express').collection('users');

For the photo page to work, go to Pixabay and register for an account. Then go to the docs page, copy your given API key and replace <API_KEY> in the Axios request of the photos page.

Else, you can set up your own backend solution for photos and the frontend should fit to suit.

Create a Fontawesome kit and replace the one already in the <head> of client/public/index.html.

Then it will be available at http://localhost:8080.

From scratch

Express

  1. npm init
  2. npm i express cors mongodb dotenv bcryptjs jsonwebtoken compression helmet nodemailer morgan

In package.json replace

  1. "scripts": {
  2. "test": "echo \"Error: no test specified\" && exit 1"
  3. },

with

  1. "scripts": {
  2. "start": "node server/server.js",
  3. "serve": "npm run serve --prefix client",
  4. },

Vue

  1. npm i -g @vue/cli #If not already installed
  2. vue create client
  3. cd client
  4. npm i axios vue-outside-events vue-meta vue-lazyload vue-scrollactive vue-toasted

Deploy to Heroku

Vue

  1. cd client
  2. npm run build

Heroku

Make an account if you haven’t already.

Then from your terminal:

  1. heroku login
  2. heroku create <your-app-name>

Then go to https://dashboard.heroku.com/apps click on your app, click ‘deploy’, choose the GitHub deployment method and follow the instructions.

Also, go to your apps settings and set config vars matching your root .env variables. Set a config var for VUE_APP_NODE_ENV but add a value of production instead of development, then add another variable with a key of NODE_ENV and value of production.

Troubleshooting

If you’ve chosen automatic GitHub deployment on Heroku and something isn’t working, try manually deploying instead, sometimes the automatic deployment can act a little strange.

In MongoDB Atlas go to network access and allow IP addresses from anywhere or add specific IP addresses if known.

Make sure you run npm run build in /client before deploying or your changes won’t be served.

If you’re having trouble with Sass, make sure to install Live Sass Compiler (if using VSCode, otherwise consult the docs) and configure your settings.json to include this:

  1. "liveSassCompile.settings.formats": [
  2. {
  3. "format": "compressed",
  4. "extensionName": ".min.css",
  5. "savePath": "/client/public/css"
  6. }
  7. ],

Otherwise, it may be an error on my end so submit an issue if you think this is the case.

Credit

Credit to Brad Traversy for providing most of this code from his tutorials. To learn more about this repo check out his videos covering both MERN and MEVN.