Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
ee5e375
Added mongoose, seed data and fetch + display data
smax22 May 13, 2016
823a189
Addes user signup, signin, route protection, validation
smax22 May 26, 2016
97ec0b4
Added cart/ session functionality
smax22 Jun 14, 2016
834cc25
Added Stripe functionality (anonymous)
smax22 Jul 4, 2016
67988f9
finished order storage
smax22 Jul 14, 2016
513241c
finishing touches, cart management
smax22 Jul 26, 2016
bfbb720
Tela de Cadastro + Proteção CSRF
brenohq Sep 12, 2016
14e8ca5
Cadastro com passportJS
brenohq Sep 12, 2016
493a2e5
integração com travis ci
brenohq Sep 13, 2016
68d1eed
integração com travis ci
brenohq Sep 13, 2016
e350f6c
integração com travis ci
brenohq Sep 13, 2016
3ef0980
ajustes para integração
brenohq Sep 13, 2016
0d67cd3
package.json ajdustments
brenohq Sep 13, 2016
68108f6
Signin Screen and grouping /user routes
brenohq Sep 13, 2016
6806103
Protecting routes + logout function
brenohq Sep 13, 2016
4131644
Checkout View integration with Cart
brenohq Sep 17, 2016
1bc1f0d
minor fixes
brenohq Oct 1, 2016
62c1f05
minor fixes
brenohq Oct 12, 2016
12753ef
changing Stripe API Keys
brenohq Oct 19, 2016
52b4aef
adding Jasmine to the project
brenohq Oct 19, 2016
94bbfdf
travis ci integration
brenohq Oct 19, 2016
9122336
adaptação das views para pt-br
brenohq Oct 28, 2016
68e3444
atualização do README
brenohq Oct 28, 2016
f477516
fixing hbs templates
brenohq Nov 10, 2016
cd8faa7
adicionando informações de usuário na rota /user/profile
brenohq Dec 12, 2016
dd86586
Perfil de Usuário funcionando corretamente
brenohq Dec 13, 2016
70775b6
heroku adjusts
brenohq Dec 19, 2016
e2c5b6f
heroku adjusts
brenohq Dec 19, 2016
daf05b8
pass
brenohq Dec 20, 2016
4b9332d
pass
brenohq Dec 20, 2016
ce06f90
pass
brenohq Dec 20, 2016
9f3a3e9
pass
brenohq Dec 20, 2016
e44ebce
pass
brenohq Dec 21, 2016
cdf8439
pass
brenohq Dec 21, 2016
49ae72b
pass
brenohq Dec 21, 2016
3a6289e
pass
brenohq Dec 21, 2016
d59e699
pass
brenohq Dec 21, 2016
05c9913
adding email and passwd form-groups to updateProfile
brenohq Feb 20, 2017
920effc
fix
brenohq Feb 22, 2017
3372d28
adding favicon
brenohq Feb 22, 2017
b3b2bea
performing crud operations. TODO: report errors to user and protect r…
brenohq Feb 23, 2017
7606f5b
update README
brenohq Mar 8, 2017
f0737b9
removing user working
brenohq Mar 11, 2017
003e6fe
merging development into master
brenohq Mar 11, 2017
d9580fb
adding Cart tests and minor fixes
brenohq Mar 12, 2017
ef9055a
adding tests for User
brenohq Mar 12, 2017
81cb1b6
adicionando testes para o usuário
brenohq Mar 21, 2017
76e633e
refatorando testes do mongoose para userSpec.js
brenohq Mar 21, 2017
5947318
adicionando configurações pra deploy no Heroku
brenohq Mar 21, 2017
2d1d31d
adicionando serviço mongodb no Travis CI
brenohq Mar 21, 2017
561b5b2
adicionando serviço mongodb no Travis CI
brenohq Mar 21, 2017
ed7dc67
atualizando npm scripts e adicionando nodemon como dev dependencie
brenohq Mar 21, 2017
3130437
mudando localhost hardcoded para variavel de ambiente
brenohq Mar 21, 2017
7f0a845
mudando product seeder para jogos de ps4
brenohq Mar 21, 2017
801a807
atualizando README.MD
brenohq Mar 22, 2017
831353c
atualizando README.MD
brenohq Mar 22, 2017
a4f8d5a
merging dev into master branch
brenohq Mar 22, 2017
ebd4d31
merging dev into master branch
brenohq Mar 22, 2017
3a8cf11
updating readme.md
brenohq Mar 22, 2017
1407023
changing mPromise to globalPromise
brenohq Mar 22, 2017
68a6c31
updating readme
brenohq Mar 22, 2017
543bb06
updating readme and using global.Promise insetead mpromise
brenohq Mar 22, 2017
6982e31
refatorando testes
brenohq Mar 24, 2017
7192620
fix Stripe error message
brenohq Mar 24, 2017
0df05b8
refatorando testes
brenohq Mar 24, 2017
f694134
indentando templates
brenohq Oct 10, 2019
1ea7ef9
indentando testes
brenohq Oct 10, 2019
2ca05cb
indentando arquivos public
brenohq Oct 10, 2019
76a8e24
indentando models
brenohq Oct 10, 2019
a20f8fe
indentando routes
brenohq Oct 10, 2019
f343539
indentando arquivos com 2 espaços
brenohq Oct 10, 2019
85a69e3
using useMongoClient recommended option
brenohq Oct 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.idea
/node_modules
npm-debug.log
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- 'v7.2.1'
services: mongodb
env:
- MONGO_DB_URI=mongodb://root:root@ds137220.mlab.com:37220/shoppingcart-db
Empty file modified LICENSE.MD
100644 → 100755
Empty file.
43 changes: 41 additions & 2 deletions README.MD
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
## Tutorial on How to Build a Shopping Cart with NodeJS/ Express
[![Build Status](https://travis-ci.org/brenohq/nodejs-shopping-cart.svg?branch=master)](https://travis-ci.org/brenohq/nodejs-shopping-cart)

This repository holds the source code of my YouTube series on how to create a shopping cart with NodeJS/Express/MongoDB
# NerdStore - Carrinho de Compras - NodeJS/Express

# Live Demo on Heroku:
[nodejs-shopping-cart.herokuapp.com](https://nodejs-shopping-cart.herokuapp.com/)

### Run Locally on Your Machine
You need Node, NPM and MongoDB properly installed.

Clone this repository
``` shell
git clone https://github.com/brenohq/nodejs-shopping-cart.git
```
Setup the environment variables replacing <MONGODB-PORT> with your mongodb port, usually is 27017.
``` shell
export MONGO_DB_URI=mongodb://localhost:<MONGODB-PORT>/shopping
```
Install dependencies
``` shell
npm install
```

With your mongod service running, this will populate shopping database
``` shell
node seed/product-seeder.js
```
This will start dev server at http://localhost:3000 with Nodemon.
``` shell
npm run dev
```

### Tests
``` shell
npm test
```

### Technologies
###### Back-end
NodeJS, Express, MongoDB, Mongoose.
###### Fron-end
Handlebars and Bootstrap.
96 changes: 62 additions & 34 deletions app.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var expressHbs = require('express-handlebars');
var express = require("express")
var path = require("path")
var favicon = require("serve-favicon")
var logger = require("morgan")
var cookieParser = require("cookie-parser")
var bodyParser = require("body-parser")
var expressHbs = require("express-handlebars")
var mongoose = require("mongoose")
var session = require("express-session")
var passport = require("passport")
var flash = require("connect-flash")
var validator = require("express-validator")
var MongoStore = require("connect-mongo")(session)

var routes = require('./routes/index');
var routes = require("./routes/index")
var userRoutes = require("./routes/user")

var app = express();
var app = express()

mongoose.connect(process.env.MONGO_DB_URI, { useMongoClient: true })
require("./config/passport")

// view engine setup
app.engine('.hbs', expressHbs({defaultLayout: 'layout', extname: '.hbs'}));
app.set('view engine', '.hbs');
app.engine(".hbs", expressHbs({ defaultLayout: "layout", extname: ".hbs" }))
app.set("view engine", ".hbs")

app.use(favicon(path.join(__dirname, "public", "favicon.ico")))
app.use(logger("dev"))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(validator())
app.use(cookieParser())
app.use(
session({
secret: "mysupersecret",
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
cookie: { maxAge: 180 * 60 * 1000 }
})
)
app.use(flash())
app.use(passport.initialize())
app.use(passport.session())
app.use(express.static(path.join(__dirname, "public")))

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next) {
res.locals.login = req.isAuthenticated()
res.locals.session = req.session
next()
})

app.use('/', routes);
app.use("/user", userRoutes)
app.use("/", routes)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
var err = new Error("Not Found")
err.status = 404
next(err)
})

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
if (app.get("env") === "development") {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
res.status(err.status || 500)
res.render("error", {
message: err.message,
error: err
});
});
})
})
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
res.status(err.status || 500)
res.render("error", {
message: err.message,
error: {}
});
});

})
})

module.exports = app;
module.exports = app
60 changes: 28 additions & 32 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,74 @@
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('shopping-cart:server');
var http = require('http');
var app = require("../app")
var debug = require("debug")("shopping-cart:server")
var http = require("http")

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
var port = normalizePort(process.env.PORT || "3000")
app.set("port", port)

/**
* Create HTTP server.
*/

var server = http.createServer(app);
var server = http.createServer(app)

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
server.listen(port)
server.on("error", onError)
server.on("listening", onListening)

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);
var port = parseInt(val, 10)

if (isNaN(port)) {
// named pipe
return val;
return val
}

if (port >= 0) {
// port number
return port;
return port
}

return false;
return false
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
if (error.syscall !== "listen") {
throw error
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
var bind = typeof port === "string" ? "Pipe " + port : "Port " + port

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
case "EACCES":
console.error(bind + " requires elevated privileges")
process.exit(1)
break
case "EADDRINUSE":
console.error(bind + " is already in use")
process.exit(1)
break
default:
throw error;
throw error
}
}

Expand All @@ -82,9 +80,7 @@ function onError(error) {
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
var addr = server.address()
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port
debug("Listening on " + bind)
}
Loading