├── .editorconfig ├── .gitignore ├── README.md ├── api ├── config.js ├── controllers │ ├── articlesController.js │ └── usersController.js ├── db.js ├── index.js ├── models │ ├── Article.js │ └── User.js └── routes │ ├── articles.js │ └── users.js ├── assets └── README.md ├── components ├── Logo.vue └── README.md ├── layouts ├── README.md └── default.vue ├── middleware └── README.md ├── nuxt.config.js ├── package-lock.json ├── package.json ├── pages ├── README.md ├── articles │ ├── _id │ │ ├── index.vue │ │ └── update.vue │ ├── add.vue │ └── index.vue ├── index.vue └── user │ ├── login.vue │ ├── logout.vue │ ├── my-account.vue │ └── register.vue ├── plugins └── README.md ├── server └── index.js ├── static ├── README.md └── favicon.ico ├── store ├── README.md └── index.js └── todo.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | # Runtime data 11 | pids 12 | *.pid 13 | *.seed 14 | *.pid.lock 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (https://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | jspm_packages/ 40 | 41 | # TypeScript v1 declaration files 42 | typings/ 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional eslint cache 48 | .eslintcache 49 | 50 | # Optional REPL history 51 | .node_repl_history 52 | 53 | # Output of 'npm pack' 54 | *.tgz 55 | 56 | # Yarn Integrity file 57 | .yarn-integrity 58 | 59 | # dotenv environment variables file 60 | .env 61 | 62 | # parcel-bundler cache (https://parceljs.org/) 63 | .cache 64 | 65 | # next.js build output 66 | .next 67 | 68 | # nuxt.js build output 69 | .nuxt 70 | 71 | # Nuxt generate 72 | dist 73 | 74 | # vuepress build output 75 | .vuepress/dist 76 | 77 | # Serverless directories 78 | .serverless 79 | 80 | # IDE / Editor 81 | .idea 82 | 83 | # Service worker 84 | sw.* 85 | 86 | # Mac OSX 87 | .DS_Store 88 | 89 | # Vim swap files 90 | *.swp 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuxt-with-express 2 | 3 | My Boilerplate CRUD project built with [**Express**](https://expressjs.com/) as server side language, [**NuxtJS**](https://nuxtjs.org/) as frontend framework and [**Mongodb**](https://www.mongodb.com/) as database server. 4 | 5 | ## Features Implemented 6 | 7 | 1. CRUD With Express API 8 | 2. Form Validations using [**express-validator**](https://express-validator.github.io/docs/) 9 | 3. Simple notifications for crud actions 10 | 4. Authentication using [**jwtwebtoken**](https://www.npmjs.com/package/jsonwebtoken) and [**@nuxtjs/auth**](https://auth.nuxtjs.org/) module. 11 | 12 | 13 | 14 | ## Build Setup 15 | 16 | ``` bash 17 | # install dependencies 18 | $ npm run install 19 | 20 | # serve with hot reload at localhost:3000 21 | $ npm run dev 22 | 23 | # build for production and launch server 24 | $ npm run build 25 | $ npm run start 26 | 27 | # generate static project 28 | $ npm run generate 29 | ``` 30 | 31 | For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org). 32 | -------------------------------------------------------------------------------- /api/config.js: -------------------------------------------------------------------------------- 1 | const jwt = require('jsonwebtoken'); 2 | 3 | const config = { 4 | authSecret:'mysecret', 5 | } 6 | 7 | module.exports = config 8 | 9 | module.exports.isAuthenticated = function (req, res, next) { 10 | var token = req.headers.authorization 11 | if (token) { 12 | // verifies secret and checks if the token is expired 13 | jwt.verify(token.replace(/^Bearer\s/, ''), config.authSecret, function(err, decoded) { 14 | if (err) { 15 | return res.status(401).json({message: 'unauthorized'}) 16 | } else { 17 | return next(); 18 | } 19 | }); 20 | } 21 | else{ 22 | return res.status(401).json({message: 'unauthorized'}) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /api/controllers/articlesController.js: -------------------------------------------------------------------------------- 1 | const Article = require('../models/Article'); 2 | const validator = require('express-validator'); 3 | 4 | // Get all 5 | module.exports.list = function (req, res, next) { 6 | Article.find({}, function(err, articles){ 7 | if(err) { 8 | return res.status(500).json({ 9 | message: 'Error getting records.' 10 | }); 11 | } 12 | return res.json(articles); 13 | }); 14 | } 15 | 16 | 17 | // Get one 18 | module.exports.show = function(req, res) { 19 | var id = req.params.id; 20 | Article.findOne({_id: id}, function(err, article){ 21 | if(err) { 22 | return res.status(500).json({ 23 | message: 'Error getting record.' 24 | }); 25 | } 26 | if(!article) { 27 | return res.status(404).json({ 28 | message: 'No such record' 29 | }); 30 | } 31 | return res.json(article); 32 | }); 33 | } 34 | 35 | 36 | // Create 37 | module.exports.create = [ 38 | // validations rules 39 | validator.body('title', 'Please enter Article Title').isLength({ min: 1 }), 40 | validator.body('title').custom(value => { 41 | return Article.findOne({title:value}).then(article => { 42 | if (article !== null) { 43 | return Promise.reject('Title already in use'); 44 | } 45 | }) 46 | }), 47 | validator.body('author', 'Please enter Author Name').isLength({ min: 1 }), 48 | validator.body('body', 'Please enter Article Content').isLength({ min: 1 }), 49 | 50 | function(req, res) { 51 | // throw validation errors 52 | const errors = validator.validationResult(req); 53 | if (!errors.isEmpty()) { 54 | return res.status(422).json({ errors: errors.mapped() }); 55 | } 56 | 57 | // initialize record 58 | var article = new Article({ 59 | title : req.body.title, 60 | author : req.body.author, 61 | body : req.body.body, 62 | }) 63 | 64 | // save record 65 | article.save(function(err, article){ 66 | if(err) { 67 | return res.status(500).json({ 68 | message: 'Error saving record', 69 | error: err 70 | }); 71 | } 72 | return res.json({ 73 | message: 'saved', 74 | _id: article._id 75 | }); 76 | }) 77 | } 78 | ] 79 | 80 | // Update 81 | module.exports.update = [ 82 | // validation rules 83 | validator.body('title', 'Please enter Article Title').isLength({ min: 1 }), 84 | validator.body('title').custom( (value, {req}) => { 85 | return Article.findOne({ title:value, _id:{ $ne: req.params.id } }) 86 | .then( article => { 87 | if (article !== null) { 88 | return Promise.reject('Title already in use'); 89 | } 90 | }) 91 | }), 92 | validator.body('author', 'Please enter Author Name').isLength({ min: 1 }), 93 | validator.body('body', 'Please enter Article Content').isLength({ min: 1 }), 94 | 95 | function(req, res) { 96 | // throw validation errors 97 | const errors = validator.validationResult(req); 98 | if (!errors.isEmpty()) { 99 | return res.status(422).json({ errors: errors.mapped() }); 100 | } 101 | 102 | var id = req.params.id; 103 | Article.findOne({_id: id}, function(err, article){ 104 | if(err) { 105 | return res.status(500).json({ 106 | message: 'Error saving record', 107 | error: err 108 | }); 109 | } 110 | if(!article) { 111 | return res.status(404).json({ 112 | message: 'No such record' 113 | }); 114 | } 115 | 116 | // initialize record 117 | article.title = req.body.title ? req.body.title : article.title; 118 | article.author = req.body.author ? req.body.author : article.author; 119 | article.body = req.body.body ? req.body.body : article.body; 120 | 121 | // save record 122 | article.save(function(err, article){ 123 | if(err) { 124 | return res.status(500).json({ 125 | message: 'Error getting record.' 126 | }); 127 | } 128 | if(!article) { 129 | return res.status(404).json({ 130 | message: 'No such record' 131 | }); 132 | } 133 | return res.json(article); 134 | }); 135 | }); 136 | } 137 | 138 | ] 139 | 140 | 141 | // Delete 142 | module.exports.delete = function(req, res) { 143 | var id = req.params.id; 144 | Article.findByIdAndRemove(id, function(err, article){ 145 | if(err) { 146 | return res.status(500).json({ 147 | message: 'Error getting record.' 148 | }); 149 | } 150 | return res.json(article); 151 | }); 152 | } 153 | -------------------------------------------------------------------------------- /api/controllers/usersController.js: -------------------------------------------------------------------------------- 1 | const config = require('../config') 2 | const User = require('../models/User') 3 | const validator = require('express-validator') 4 | const jwt = require('jsonwebtoken'); 5 | const bcrypt = require('bcryptjs') 6 | 7 | 8 | // Register 9 | module.exports.register = [ 10 | // validations rules 11 | validator.body('full_name', 'Please enter Full Name').isLength({ min: 1 }), 12 | validator.body('email', 'Please enter Email').isLength({ min: 1 }), 13 | validator.body('email').custom(value => { 14 | return User.findOne({email:value}).then(user => { 15 | if (user !== null) { 16 | return Promise.reject('Email already in use'); 17 | } 18 | }) 19 | }), 20 | validator.body('password', 'Please enter Password').isLength({ min: 1 }), 21 | 22 | function(req, res) { 23 | // throw validation errors 24 | const errors = validator.validationResult(req); 25 | if (!errors.isEmpty()) { 26 | return res.status(422).json({ errors: errors.mapped() }); 27 | } 28 | 29 | // initialize record 30 | var user = new User({ 31 | full_name : req.body.full_name, 32 | email : req.body.email, 33 | password : req.body.password, 34 | }) 35 | 36 | // encrypt password 37 | var salt = bcrypt.genSaltSync(10); 38 | var hash = bcrypt.hashSync(user.password, salt); 39 | user.password = hash 40 | 41 | // save record 42 | user.save(function(err, user){ 43 | if(err) { 44 | return res.status(500).json({ 45 | message: 'Error saving record', 46 | error: err 47 | }); 48 | } 49 | return res.json({ 50 | message: 'saved', 51 | _id: user._id 52 | }); 53 | }) 54 | } 55 | ] 56 | 57 | 58 | // Login 59 | module.exports.login = [ 60 | // validation rules 61 | validator.body('email', 'Please enter Email').isLength({ min: 1 }), 62 | validator.body('password', 'Please enter Password').isLength({ min: 1 }), 63 | 64 | function(req, res) { 65 | // throw validation errors 66 | const errors = validator.validationResult(req); 67 | if (!errors.isEmpty()) { 68 | return res.status(422).json({ errors: errors.mapped() }); 69 | } 70 | 71 | // validate email and password are correct 72 | User.findOne({email: req.body.email}, function(err, user){ 73 | if(err) { 74 | return res.status(500).json({ 75 | message: 'Error logging in', 76 | error: err 77 | }); 78 | } 79 | 80 | if (user === null) { 81 | return res.status(500).json({ 82 | message: 'Email address you entered is not found.' 83 | }); 84 | } 85 | 86 | // compare submitted password with password inside db 87 | return bcrypt.compare(req.body.password, user.password, function(err, isMatched) { 88 | if(isMatched===true){ 89 | return res.json({ 90 | user: { 91 | _id: user._id, 92 | email: user.email, 93 | full_name: user.full_name 94 | }, 95 | token: jwt.sign({_id: user._id, email: user.email, full_name: user.full_name}, config.authSecret) // generate JWT token here 96 | }); 97 | } 98 | else{ 99 | return res.status(500).json({ 100 | message: 'Invalid Email or Password entered.' 101 | }); 102 | } 103 | }); 104 | }); 105 | } 106 | ] 107 | 108 | // Get User 109 | module.exports.user = function(req, res) { 110 | var token = req.headers.authorization 111 | if (token) { 112 | // verifies secret and checks if the token is expired 113 | jwt.verify(token.replace(/^Bearer\s/, ''), config.authSecret, function(err, decoded) { 114 | if (err) { 115 | return res.status(401).json({message: 'unauthorized'}) 116 | } else { 117 | return res.json({ user: decoded }) 118 | } 119 | }); 120 | } 121 | else{ 122 | return res.status(401).json({message: 'unauthorized'}) 123 | } 124 | } 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /api/db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | mongoose.connect('mongodb://localhost/nodekb', { 3 | useNewUrlParser: true, 4 | useUnifiedTopology: true, 5 | useFindAndModify: false, 6 | useCreateIndex: true 7 | }); 8 | var db = mongoose.connection; 9 | db.on('error', console.error.bind(console, 'connection error:')); 10 | db.once('open', function callback () { 11 | console.log("MongoDB Connected..."); 12 | }); 13 | 14 | module.exports = db 15 | -------------------------------------------------------------------------------- /api/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const db = require('./db') 3 | 4 | 5 | // Create express instnace 6 | const app = express() 7 | 8 | // Init body-parser options (inbuilt with express) 9 | app.use(express.json()); 10 | app.use(express.urlencoded({ extended: true })); 11 | 12 | 13 | // Require & Import API routes 14 | const users = require('./routes/users') 15 | const articles = require('./routes/articles') 16 | 17 | // Use API Routes 18 | app.use(users) 19 | app.use(articles) 20 | 21 | // Export the server middleware 22 | module.exports = { 23 | path: '/api', 24 | handler: app 25 | } 26 | -------------------------------------------------------------------------------- /api/models/Article.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const Schema = mongoose.Schema; 3 | 4 | const Article = new Schema ({ 5 | title: { type: String, required: true, index: { unique: true } }, 6 | author: { type: String, required: true }, 7 | body: { type: String, required: true }, 8 | }); 9 | 10 | module.exports = mongoose.model('Article', Article) 11 | -------------------------------------------------------------------------------- /api/models/User.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const Schema = mongoose.Schema; 3 | 4 | const User = new Schema ({ 5 | full_name: { type: String, required: true }, 6 | email: { type: String, required: true, index: { unique: true } }, 7 | password: { type: String, required: true }, 8 | }); 9 | 10 | module.exports = mongoose.model('User', User) 11 | -------------------------------------------------------------------------------- /api/routes/articles.js: -------------------------------------------------------------------------------- 1 | const config = require('../config') 2 | const { Router } = require('express') 3 | 4 | const router = Router() 5 | 6 | // Initialize Controller 7 | const articlesController = require('../controllers/articlesController') 8 | 9 | // Get All 10 | router.get('/articles', articlesController.list) 11 | 12 | // Get One 13 | router.get('/articles/:id', articlesController.show) 14 | 15 | // Create 16 | router.post('/articles', config.isAuthenticated, articlesController.create) 17 | 18 | // Update 19 | router.put('/articles/:id', config.isAuthenticated, articlesController.update) 20 | 21 | // Delete 22 | router.delete('/articles/:id', config.isAuthenticated, articlesController.delete) 23 | 24 | module.exports = router 25 | -------------------------------------------------------------------------------- /api/routes/users.js: -------------------------------------------------------------------------------- 1 | const config = require('../config') 2 | const { Router } = require('express') 3 | 4 | const router = Router() 5 | 6 | // Initialize Controller 7 | const usersController = require('../controllers/usersController') 8 | 9 | // Register 10 | router.post('/users/register', usersController.register) 11 | 12 | // Login 13 | router.post('/users/login', usersController.login) 14 | 15 | // Get User 16 | router.get('/users/user', usersController.user) 17 | 18 | module.exports = router 19 | -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # ASSETS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked). 8 | -------------------------------------------------------------------------------- /components/Logo.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 80 | -------------------------------------------------------------------------------- /components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | The components directory contains your Vue.js Components. 6 | 7 | _Nuxt.js doesn't supercharge these components._ 8 | -------------------------------------------------------------------------------- /layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Application Layouts. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts). 8 | -------------------------------------------------------------------------------- /layouts/default.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | -------------------------------------------------------------------------------- /middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your application middleware. 6 | Middleware let you define custom functions that can be run before rendering either a page or a group of pages. 7 | 8 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing#middleware). 9 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | mode: 'universal', 4 | /* 5 | ** Headers of the page 6 | */ 7 | head: { 8 | title: 'Express CRUD', 9 | meta: [ 10 | { charset: 'utf-8' }, 11 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 12 | { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } 13 | ], 14 | link: [ 15 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 16 | ] 17 | }, 18 | /* 19 | ** Customize the progress-bar color 20 | */ 21 | loading: { color: '#fff' }, 22 | /* 23 | ** Global CSS 24 | */ 25 | css: [ 26 | ], 27 | /* 28 | ** Plugins to load before mounting the App 29 | */ 30 | plugins: [ 31 | ], 32 | /* 33 | ** Nuxt.js dev-modules 34 | */ 35 | buildModules: [ 36 | ], 37 | /* 38 | ** Nuxt.js modules 39 | */ 40 | modules: [ 41 | // Doc: https://bootstrap-vue.js.org 42 | 'bootstrap-vue/nuxt', 43 | // Doc: https://axios.nuxtjs.org/usage 44 | '@nuxtjs/axios', 45 | '@nuxtjs/auth', 46 | ], 47 | 48 | auth: { 49 | strategies: { 50 | local: { 51 | endpoints: { 52 | login: { 53 | url: '/api/users/login', 54 | method: 'post', 55 | propertyName: 'token' 56 | }, 57 | logout: true, 58 | user: { 59 | url: '/api/users/user', 60 | method: 'get', 61 | propertyName: 'user' 62 | } 63 | }, 64 | tokenRequired: true, 65 | tokenType: "Bearer" 66 | } 67 | }, 68 | redirect: { 69 | login: '/user/login', // User will be redirected to this path if login is required 70 | logout: '/', // User will be redirected to this path if after logout, current route is protected 71 | home: '/' // User will be redirect to this path after login if accessed login page directly 72 | }, 73 | rewriteRedirects: true, 74 | }, 75 | /* 76 | ** Axios module configuration 77 | ** See https://axios.nuxtjs.org/options 78 | */ 79 | axios: { 80 | }, 81 | /* 82 | ** Build configuration 83 | */ 84 | build: { 85 | /* 86 | ** You can extend webpack config here 87 | */ 88 | extend (config, ctx) { 89 | } 90 | }, 91 | 92 | serverMiddleware: [ 93 | '~/api/index.js' 94 | ] 95 | } 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt-with-express", 3 | "version": "1.0.0", 4 | "description": "My primo Nuxt.js project", 5 | "author": "Aslam Doctor", 6 | "private": true, 7 | "scripts": { 8 | "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server", 9 | "build": "nuxt build", 10 | "start": "cross-env NODE_ENV=production node server/index.js", 11 | "generate": "nuxt generate" 12 | }, 13 | "dependencies": { 14 | "@nuxtjs/auth": "^4.8.5", 15 | "@nuxtjs/axios": "^5.9.3", 16 | "bcryptjs": "^2.4.3", 17 | "bootstrap": "^4.1.3", 18 | "bootstrap-vue": "^2.0.0", 19 | "cross-env": "^5.2.0", 20 | "express": "^4.16.4", 21 | "express-validator": "^6.3.1", 22 | "jsonwebtoken": "^8.5.1", 23 | "mongoose": "^5.8.7", 24 | "nuxt": "^2.0.0" 25 | }, 26 | "devDependencies": { 27 | "nodemon": "^1.18.9" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the `*.vue` files inside this directory and creates the router of your application. 5 | 6 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing). 7 | -------------------------------------------------------------------------------- /pages/articles/_id/index.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 55 | -------------------------------------------------------------------------------- /pages/articles/_id/update.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 105 | -------------------------------------------------------------------------------- /pages/articles/add.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 88 | -------------------------------------------------------------------------------- /pages/articles/index.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 42 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | -------------------------------------------------------------------------------- /pages/user/login.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | 79 | -------------------------------------------------------------------------------- /pages/user/logout.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 19 | -------------------------------------------------------------------------------- /pages/user/my-account.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 24 | -------------------------------------------------------------------------------- /pages/user/register.vue: -------------------------------------------------------------------------------- 1 | 50 | 51 | 99 | -------------------------------------------------------------------------------- /plugins/README.md: -------------------------------------------------------------------------------- 1 | # PLUGINS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains Javascript plugins that you want to run before mounting the root Vue.js application. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins). 8 | -------------------------------------------------------------------------------- /server/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const consola = require('consola') 3 | const { Nuxt, Builder } = require('nuxt') 4 | const app = express() 5 | 6 | // Import and Set Nuxt.js options 7 | const config = require('../nuxt.config.js') 8 | config.dev = process.env.NODE_ENV !== 'production' 9 | 10 | async function start () { 11 | // Init Nuxt.js 12 | const nuxt = new Nuxt(config) 13 | 14 | const { host, port } = nuxt.options.server 15 | 16 | // Build only in dev mode 17 | if (config.dev) { 18 | const builder = new Builder(nuxt) 19 | await builder.build() 20 | } else { 21 | await nuxt.ready() 22 | } 23 | 24 | // Give nuxt middleware to express 25 | app.use(nuxt.render) 26 | 27 | // Listen the server 28 | app.listen(port, host) 29 | consola.ready({ 30 | message: `Server listening on http://${host}:${port}`, 31 | badge: true 32 | }) 33 | } 34 | start() 35 | -------------------------------------------------------------------------------- /static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your static files. 6 | Each file inside this directory is mapped to `/`. 7 | Thus you'd want to delete this README.md before deploying to production. 8 | 9 | Example: `/static/robots.txt` is mapped as `/robots.txt`. 10 | 11 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static). 12 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aslamdoctor/nuxt-with-express/54d5230fbb02bea9b19fae564898d41f236cc72b/static/favicon.ico -------------------------------------------------------------------------------- /store/README.md: -------------------------------------------------------------------------------- 1 | # STORE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Vuex Store files. 6 | Vuex Store option is implemented in the Nuxt.js framework. 7 | 8 | Creating a file in this directory automatically activates the option in the framework. 9 | 10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store). 11 | -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aslamdoctor/nuxt-with-express/54d5230fbb02bea9b19fae564898d41f236cc72b/store/index.js -------------------------------------------------------------------------------- /todo.md: -------------------------------------------------------------------------------- 1 | # Tasks 2 | 3 | - [x] CRUD With Express API 4 | - [x] Form Validations 5 | - [x] Notifications 6 | - [x] Authentication 7 | - [x] Add security to API routes 8 | - [ ] Add CORS security 9 | - [ ] Module Relationships 10 | - [ ] File Upload 11 | --------------------------------------------------------------------------------