Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. Server Stareted On Port 3000
  2. events.js:141
  3. throw er; // Unhandled 'error' event
  4. ^
  5.  
  6. error: null value in column "id" violates not-null constraint
  7.  
  8. Server Stareted On Port 3000
  9. events.js:141
  10. throw er; // Unhandled 'error' event
  11. ^
  12.  
  13. error: syntax error at or near "WHERE"
  14.  
  15. Server Stareted On Port 3000
  16. error running query { [error: there is no parameter $1]
  17. name: 'error',
  18. length: 87,
  19. severity: 'ERROR',
  20. code: '42P02',
  21. detail: undefined,
  22. hint: undefined,
  23. position: '59',
  24. internalPosition: undefined,
  25. internalQuery: undefined,
  26. where: undefined,
  27. schema: undefined,
  28. table: undefined,
  29. column: undefined,
  30. dataType: undefined,
  31. constraint: undefined,
  32. file: 'parse_expr.c',
  33. line: '824',
  34. routine: 'transformParamRef' }
  35.  
  36. events.js:141
  37. throw er; // Unhandled 'error' event
  38. ^
  39.  
  40. error: INSERT has more expressions than target columns
  41.  
  42. var express = require('express'),
  43. path = require('path'),
  44. bodyParser = require('body-parser'),
  45. cons = require('consolidate'),
  46. dust = require('dustjs-helpers'),
  47. pg = require('pg'),
  48. app = express();
  49.  
  50. // create a config to configure both pooling behavior
  51. // and client options
  52. // note: all config is optional and the environment variables
  53. // will be read if the config is not present
  54. var config = {
  55. user: 'aleatoire', //env var: PGUSER
  56. database: 'recipebookdb', //env var: PGDATABASE
  57. password: '', //env var: PGPASSWORD
  58. port: 5432, //env var: PGPORT
  59. max: 10, // max number of clients in the pool
  60. idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
  61. };
  62.  
  63.  
  64. //this initializes a connection pool
  65. //it will keep idle connections open for 30 seconds
  66. //and set a limit of maximum 10 idle clients
  67. var pool = new pg.Pool(config);
  68.  
  69.  
  70. // Assign Dust Engine To .dust Files
  71. app.engine('dust', cons.dust);
  72.  
  73. // Set Default Ext .dust
  74. app.set('view engine', 'dust');
  75. app.set('views', __dirname + '/views');
  76.  
  77. // Set Public Folder
  78. app.use(express.static(path.join(__dirname, 'public')));
  79.  
  80. // Body Parser Middleware
  81. app.use(bodyParser.json());
  82. app.use(bodyParser.urlencoded({extended: false}));
  83.  
  84. app.get('/', function(req, res){
  85. // to run a query we can acquire a client from the pool,
  86. // run a query on the client, and then return the client to the pool
  87. pool.connect(function(err, client, done) {
  88. if(err) {
  89. return console.error('error fetching client from pool', err);
  90. }
  91. client.query('SELECT * FROM recipes', function(err, result) {
  92.  
  93. if(err) {
  94. return console.error('error running query', err);
  95. }
  96. res.render('index', {recipes: result.rows});
  97. //call `done()` to release the client back to the pool
  98. done();
  99.  
  100. });
  101. });
  102.  
  103. });
  104.  
  105. app.post('/add', function(req, res){
  106. // to run a query we can acquire a client from the pool,
  107. // run a query on the client, and then return the client to the pool
  108. pool.connect(function(err, client, done) {
  109. if(err) {
  110. return console.error('error fetching client from pool', err);
  111. }
  112. client.query('INSERT INTO recipes(name, ingredients, directions) VALUES($1, $2, $3, $4)', [req.body.name, req.body.ingredients,
  113. req.body.directions]);
  114.  
  115. done();
  116. res.redirect('/');
  117. });
  118. });
  119.  
  120. // Server
  121. app.listen(3000, function(){
  122. console.log('Server Stareted On Port 3000');
  123. });
  124.  
  125. {
  126. "name": "recipebook",
  127. "version": "1.0.0",
  128. "description": "A recipe web app with Nodejs and PostgreSQL",
  129. "main": "app.js",
  130. "scripts": {
  131. "test": "echo "Error: no test specified" && exit 1"
  132. },
  133. "author": "Daniel Cortes",
  134. "license": "ISC",
  135. "dependencies": {
  136. "body-parser": "^1.15.2",
  137. "consolidate": "*",
  138. "dust": "*",
  139. "dustjs-helpers": "*",
  140. "dustjs-linkedin": "*",
  141. "express": "*",
  142. "pg": "*"
  143. }
  144. }
  145.  
  146. <!DOCTYPE html>
  147. <html>
  148. <head>
  149. <title>RecipeBook</title>
  150. <link rel="stylesheet" href="/css/bootstrap.css">
  151. <link rel ="stylesheet" href="/css/style.css">
  152. </head>
  153. <body>
  154. <div class="container">
  155. <div class="row">
  156. <div class="col-md-offset-2 col-md-7">
  157. {+body /}
  158. </div>
  159. </div>
  160. </div>
  161. <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
  162. <script src="/js/bootstrap.js"></script>
  163. </body>
  164. </html>
  165.  
  166. {>"layout" /}
  167.  
  168. {<body}
  169. <button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#formModal">
  170. Add Recipe
  171. </button>
  172.  
  173. <br />
  174.  
  175. {#recipes}
  176. <div class="well">
  177. <h4>{name}
  178. <button class="btn btn-default pull-right" data-toggle="collapse" href="#recipe_{id}" aria-expanded="false" aria-controls="recipe_{id}">
  179. <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
  180. </button></h4>
  181.  
  182. <div class="collapse" id="recipe_{id}">
  183. <br />
  184. <br />
  185. <p><strong>Ingredients: </strong>{ingredients}</p>
  186. <p><strong>Directions: </strong>{directions}</p>
  187. <br />
  188. <hr />
  189. <button class="btn btn-default edit-recipe">
  190. <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
  191. </button>
  192. <button class="btn btn-danger delete-recipe">
  193. <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
  194. </button>
  195. </div>
  196. </div>
  197. {/recipes}
  198.  
  199. <!-- Add Form Modal -->
  200. <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel">
  201. <div class="modal-dialog" role="document">
  202. <div class="modal-content">
  203. <form method="post" action="/add">
  204. <div class="modal-header">
  205. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  206. <h4 class="modal-title" id="myModalLabel">Add Recipe</h4>
  207. </div>
  208. <div class="modal-body">
  209. <div class="form-group">
  210. <label>Recipe Name</label>
  211. <input type="text" class="form-control" name="name" />
  212. </div>
  213. <div class="form-group">
  214. <label>Ingredients</label>
  215. <textarea name="ingredients" class="form-control"></textarea>
  216. </div>
  217. <div class="form-group">
  218. <label>Directions</label>
  219. <textarea class="form-control" name="directions"></textarea>
  220. </div>
  221. </div>
  222. <div class="modal-footer">
  223. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  224. <input type="submit" class="btn btn-primary" value="Save" />
  225. </div>
  226. </form>
  227. </div>
  228. </div>
  229. </div>
  230. {/body}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement