Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
93 changes: 17 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,27 @@
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://admin:admin1@ds243812.mlab.com:43812/cas8mern";

var db;

var express = require('express');
var app = express();
var session = require('express-session');
var cookieParser = require('cookie-parser');
var port = 8000;

var book = require('./book');

var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine', 'ejs');

app.listen(8000);

MongoClient.connect(url, function(err, client){
if(err) console.log(err);

else{
db = client.db('cas8mern');
console.log("DB connected");
}


});


app.get('/', (req, res) =>{

res.send("ok");
})


app.get('/newBook', (req, res) =>{
var passport = require('passport');

res.render('newBook');
})
var url = "mongodb://admin:admin1@ds243812.mlab.com:43812/cas8mern"
var mongoose = require('mongoose');

app.post('/newBook', (req, res) =>{
let name = req.body.title;
let author = req.body.author;
let year = req.body.year;
let genre = req.body.genre;
app.use(session({
secret: 'mern'
}));


let b = new book.create(name, author, year, genre);

console.log(b);

db.collection("books").insertOne(b, (err) => {
if(err) console.log("err");
else{
console.log("1 document inserted");
res.redirect('allBooks');
}
})

})


app.get('/allBooks', (req, res) =>{
db.collection('books').find({}).toArray((err, items) => {
console.log(items);

res.render('books', {books: items});
})


})


app.get('/book', (req, res) =>{
console.log('ok');
console.log(req.query.id);
// db.collection('books').find({author: "Danielle Steel"}).toArray((err, items) => {
// console.log(items);

// //res.render('books', {books: items});
// })
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'ejs');


})
require('./app/routes.js')(app);
require('./config/passport.js')(passport);

app.listen(port, passport);

mongoose.connect(url);
47 changes: 47 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@3.10.10
3 info using node@v6.11.4
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle cas9@1.0.0~prestart: cas9@1.0.0
6 silly lifecycle cas9@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle cas9@1.0.0~start: cas9@1.0.0
8 verbose lifecycle cas9@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle cas9@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\moc\Desktop\node\cas9\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files\nodejs\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Users\moc\AppData\Local\Microsoft\WindowsApps;
10 verbose lifecycle cas9@1.0.0~start: CWD: C:\Users\moc\Desktop\node\cas9
11 silly lifecycle cas9@1.0.0~start: Args: [ '/d /s /c', 'node index.js' ]
12 silly lifecycle cas9@1.0.0~start: Returned: code: 1 signal: null
13 info lifecycle cas9@1.0.0~start: Failed to exec start script
14 verbose stack Error: cas9@1.0.0 start: `node index.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:920:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
15 verbose pkgid cas9@1.0.0
16 verbose cwd C:\Users\moc\Desktop\node\cas9
17 error Windows_NT 10.0.16299
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
19 error node v6.11.4
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error cas9@1.0.0 start: `node index.js`
22 error Exit status 1
23 error Failed at the cas9@1.0.0 start script 'node index.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the cas9 package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node index.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs cas9
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls cas9
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node",
"name": "cas9",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand All @@ -10,8 +10,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"bcrypt-nodejs": "0.0.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.3",
"mongodb": "^3.1.4"
"mongoose": "^5.2.13",
"passport": "^0.4.0"
}
}