This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$('input#update').click(function() { | |
var clave = $('#keys').val(); | |
var valor = $('#value').val(); | |
var arr = {}; | |
arr[clave] = valor; | |
console.log(arr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctype html | |
html(lang='es') | |
head | |
meta(charset='utf-8') | |
meta(name='description', content='APIRest_test') | |
meta(name='keywords', content='API, rest, node, mongo, mongoose, html5, express') | |
title= title | |
link(rel='stylesheet', href='/stylesheets/style.css') | |
script(type="text/javascript", src="http://code.jquery.com/jquery-1.11.0.min.js") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout | |
block content | |
article | |
div.addCommentForm | |
form( method="post", action="/api/entries") | |
div | |
div | |
span.label Name : | |
input(name="name") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require( './routes/model_db' ); | |
var express = require('express'); | |
var routes = require('./routes'); | |
var http = require('http'); | |
var path = require('path'); | |
var app = express(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "application-name", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "node app.js" | |
}, | |
"devDependencies": {}, | |
"dependencies": { | |
"express": "3.4.8", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "application-name", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "node app.js" | |
}, | |
"devDependencies": { | |
"nodemon" : "*", | |
"pm2" : "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require( 'mongoose' ); | |
var Schema = mongoose.Schema; | |
var Model = new Schema({ | |
name : String, | |
surname : String, | |
age : Number | |
}); | |
var regModel = mongoose.model( 'Model_name', Model ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require( 'mongoose' ); | |
var regModel = mongoose.model( 'Model_name'); | |
exports.getAll = function (req, res){ | |
regModel.find(function (err, entries) { | |
if (!err) { | |
res.render( 'index', { | |
title : 'RestAPI System with Mongoose and Node/Express', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.postnew = function (req, res){ | |
var entry; | |
console.log("POST: " + req.params + req.body + req.query); | |
entry = new regModel(); | |
for (key in req.body){ | |
entry[key] = req.body[key]; | |
} | |
entry.save(function (err) { | |
if (!err) { | |
console.log("created"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.putById = function (req, res){ | |
console.log(req.body); | |
regModel.findById(req.params.id, function (err, entry) { | |
for (key in req.body){ | |
entry[key] = req.body[key]; | |
} | |
entry.save(function (err) { | |
if (!err) { | |
console.log("updated"); |
OlderNewer