[nodejs] cannot register user with bcrypt postgreSQL Ask

2017-05-19 Thread filipecostaa10

1down votefavorite 


I am using nodejs + postgreSQL to do the registration of my app, so i have 
this basic model:

"use strict";var sequelize = require('./index');var bcrypt = 
require('bcryptjs');
module.exports = function (sequelize, DataTypes) {
  var User = sequelize.define("User", {
username: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING
  }, {
instanceMethods: {
generateHash: function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
},
validPassword: function(password) {
return bcrypt.compareSync(password, this.password);
},
}});

  return User;};

it worked before when i didn't had the password, now i want to hash that 
password and salt, so in my register route i have this:

var express = require('express');var User = 
require('../../models').User;var router = express.Router();
/* GET users listing. */
router.post('/', function (req, res, next) {

  if (JSON.stringify(req.body) == "{}") {
return res.status(400).json({ Error: "Register request body is empty" });
  }
  if (!req.body.email || !req.body.username || !req.body.password) {
return res.status(400).json({ Error: "Missing fields for registration" });
  }

  var password = User.generateHash(req.body.password);

  User.create({
username: req.body.username,
email: req.body.email,
password: password
  }).then(function () {
return res.status(200).json({message: "user created"});
  })
});
module.exports = router;

now i just don't get any response of my postman and the row isn't saving on 
the databse any sugestion?

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b6a7a175-3c86-4b2f-a785-32862bb065d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Cannot find name 'object' in angular 2 cli ckeditor

2017-05-19 Thread Deepak Kumar


Hi,
I have insalled ng2-ckeditor using cli :- npm install ng2-ckeditor --save
Then Include CKEditor javascript files in my index file :- https://cdn.ckeditor.com/4.5.11/full/ckeditor.js";>
Then imported module in module file:
import { CKEditorModule } from 'ng2-ckeditor';
in imports "CKEditorModule"

and trying to use in html


It show error:
ERROR in 
/var/www/html/eventswebsite/frontendapp/node_modules/ng2-ckeditor/lib/ckeditor.component.d.ts
 
(43,26): Cannot find name 'object'.

"ng2-ckeditor/lib/ckeditor.component.d.ts (43,26): Cannot find name 
'object'."

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/86ae50a6-4359-49f4-95a8-4d2cdfdfacc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Poor response times with mssql module

2017-05-19 Thread Victor Espina
Thanks for your answer and your tips.  I am still new to this NodeJS / 
Javascript programming, specially regarding promises.  I tried a simplified 
version of the code test, just to leave out anything that may be getting on 
the way, but the times remained the same:


function queryTest2(req, res, next) {
  var config = require("../config");
  var sql = require("mssql");
  console.time("Total request time");
  console.time("sql.connect");
  var pool = sql.connect(config.db)
.then(function(pool) {
  console.timeEnd("sql.connect");
  var request = pool.request();
  console.time("request.query");
  return request.query("SELECT clave, texto FROM registro");
})
.then(function(result) {
  console.timeEnd("request.query");
  console.timeEnd("Total request time");
  res.send(result);
})
.catch(function(err) {
  res.send(err);
});
}



Also, I tried with another packaged called "Seriate", based on mssql 
package, and times were exactly what I was expecting for: < 1s, so 
definitely the problem is in my code but I still can't figure it out what I 
am doing wrong.


Victor

El martes, 18 de abril de 2017, 21:42:02 (UTC-3), ThomasP. escribió:
>
> Hi, 
>
> I' am a little bit confused. Why do you wrap a Promise into Promises? 
> It does not make sense, because Promises themselves check if the 
> returned value is a promise, so the promise pipeline does what you do 
> internally. There is no need of try/catch, if you do no error handling. 
> The Promise mechanics wraps your function into a try/catch block. Do 
> only the transformation in the fullfill function and catch the error in 
> an reject function and handle it there. 
>
> var resolver = function(resolve, reject) { 
> > try { 
> >   console.time("connecting"); 
> >   dbcp.connect() 
> >   .then(runSelect) 
> >   .then(returnResults) 
> >   .then(resolve) 
> >   .catch(reject); 
> > } catch (err) { 
> >   reject(err); 
> > } 
> >   } 
>
> Instead of using such methods write this. 
>
> console.time("connecting"); 
> return dbcp.connect() 
>.then(runSelect) 
>.then(returnResults); 
>
> Every time, you run new dbHelper, you have a synchronized calls on the 
> require method. It could be possible that there is your bottle neck. All 
> things, that you require, you should require on the top of your module, 
> not in functions, methods. 
>
> I hope it will help a little bit. 
>
>
> Thomas 
>
>
> Am 10.04.2017 um 16:14 schrieb Victor Espina: 
> > Hi.  I am new to node.js I am trying to create a REST service (using 
> > Express) that access data from a SQL Server.  I am using mssql module 
> > with Tedious drivers.  I created this  module: 
> > 
> > /* 
> >   dbhelper.js 
> >   Helper para acceso a base de datos 
> > 
> >   Victor Espina S 
> >   NOI Quality Software, Chile 
> > */ 
> > 
> > function dbhelper(params) { 
> > 
> >   // Properties 
> >   this.dbcp = params.dbcp; // DB ConnectionsPool object (created in 
> app.js) 
> >   this.config = require("../config"); 
> > 
> >   // Methods 
> >   this.runQuery = runQuery; 
> >   this.runSP = runSP; 
> >   this.getRow = getRow; 
> >   this.getScalar = getScalar; 
> > 
> > } 
> > 
> > 
> > 
> > // runQuery 
> > // Ejecuta una consulta y devuelve el resultado 
> > // 
> > function runQuery(query) { 
> >   var sql = require('mssql'); 
> >   var dbcp = this.dbcp; 
> > 
> >   var runSelect = function(pool) { 
> > console.timeEnd("connecting"); 
> > return new Promise(function(resolve, reject) { 
> >   console.time("request"); 
> >   var request = new sql.Request(pool); 
> >   console.timeEnd("request"); 
> >   console.time("querying"); 
> >   request.query(query) 
> >  .then(resolve) 
> >  .catch(reject); 
> > }); 
> >   } 
> > 
> >   var returnResults = function(result) { 
> > console.timeEnd("querying"); 
> > return new Promise(function(resolve, reject) { 
> >   console.time("closing"); 
> >   dbcp.close(); 
> >   console.timeEnd("closing"); 
> >   resolve(result); 
> > }); 
> >   } 
> > 
> >   var resolver = function(resolve, reject) { 
> > try { 
> >   console.time("connecting"); 
> >   dbcp.connect() 
> >   .then(runSelect) 
> >   .then(returnResults) 
> >   .then(resolve) 
> >   .catch(reject); 
> > } catch (err) { 
> >   reject(err); 
> > } 
> >   } 
> > 
> >   return new Promise(resolver); 
> > } 
> > 
> > module.exports = dbhelper; 
> > 
> > 
> > 
> > and this is how I am using it: 
> > 
> > function dbTest(req, res, next) { 
> >   var dbhelper = require("../modules/dbhelper"); 
> >   var db = new dbhelper({ dbcp: res.app.locals.dbcp }); 
> >   db.runQuery("select clave,texto from 

[nodejs] Re: NodeJS REST API

2017-05-19 Thread Zlatko


On Friday, May 12, 2017 at 1:19:26 AM UTC+2, Kameron Berget wrote:
>
>
> Should the require('mssql'), config and connect statements really be 
> inside the GET? That would mean that I have to repeat the config 
> (connection) settings in each method on each endpoint. Where would be the 
> best place to put this? Also, are simple sql.connect calls ok for large 
> loads or do I need to consider connection pools, etc?  My GET method is 
> below.
>
>
Well, for one thing, the *require* itself  is cached, on process level. So 
no matter how many times you call require('mssql'), it'll only read it 
once, at that first require in the first module that actually calls it.

But that is, as you seem to suspect, most likely *not* the perf problem, 
but the fact that on each API request, you have to create a new connection. 
How it is usually done is to have a *db* module somewhere. Then you export 
a *db.bootstrap* or *db.initialize* function, and possibly a *db.client* from 
that module and other db-querying modules use that client. You call the 
init once when your server is starting, and than all other actual calls to 
the db do not have to do this step. Just make sure that before the server 
started serving

One of the exceptions to this would be when you're using something like 
Azure Functions, or AWS lambda or similar. Usually you cannot persist 
database connections there so you have to connect on each request. But 
that's probably something you ask later.

One small disclaimer is that I didn't work with Azure, but I've worked with 
other bigger infra/platform providers and they usually share those concepts 
so I'm pretty sure the above should apply to Azure App service.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/cdc779d3-56a3-4c23-a985-c6d9388c2671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Non internet facing deployment

2017-05-19 Thread Todd Lane
Hi,

I'm using Amazon & created a Node box which will sit behind a NGINX reverse 
proxy.

My question is how do you get files up to the Node server via Git on a server 
that has no internet access?

Thanks in advance 

Todd

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/c375ee0f-cfda-4db5-a9d4-4064dd3f507c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Training institute

2017-05-19 Thread sonu jatav
Hi,

Can anyone suggest me good node.js training institute in Mumbai.


Thanks
Sonu

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/289f7489-4ce0-4dec-a5ed-1fbaedbf563c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: how can i write a string data using fs

2017-05-19 Thread Zlatko
Few things, one really important:

*You shared your API token with the world!*

If you can, delete that token and in the future, replace it with a 
placeholder when you're posting examples.

Second, *request* you can handle errors in streams, e.g.

*request(options).pipe(fs.createWriteStream(filename)).on('error', err 
=> console.log(err));*

However, this is only a part of the solution - the problem is that request 
doesn't think that e.g. 404 response will be an error - it'll let you 
handle it. Check this answer: http://stackoverflow.com/a/14972828/162070

What it says is to check for the status code before creating your write 
stream, something like this:

const r = request(url)
r.on('response', function (resp) {
  if (resp.statusCode > 399) { // e.g. 400, 404 or whatever else you 
consider failure
throw new Error();
  }   
  r.pipe(new WritableStream())
});


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/ce340ce4-d6e1-40df-a623-0cd8a5ed13f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Where to host a node js app?

2017-05-19 Thread Bilal Haidar
Hi,
I am new to node js.

When developing ASP.NET for instance, I know that I need to host the app 
under IIS.

When working with node js, where and how to host an app? I am developing a 
node js app for internal use within my organization and I need to host it 
somewhere for users to use it.

do I need IIS? Is there something else?

Thanks
Bilal

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/64404eee-b8a4-4a19-925e-622f515e7aa5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] NodeJS not releasing from memory

2017-05-19 Thread J
Can anyone help me with this?

I setup a simple service that looks like this:

[Unit]
Description=nodetest

[Service]
ExecStart=/root/.nvm/versions/node/v6.10.3/bin/node /home/xxx/nodescript.js
Restart=always
# User=nobody
# Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/xxx/bin/node_modules

[Install]
WantedBy=multi-user.target



...It appears when I load it via systemctl OR JUST load it using the 
ExecStart command above... when I kill it I never get back the 30MB or 
so in RAM that the script used.

Meaning: I load the script, it runs, and it takes about 30MB of RAM. When I 
kill the script (systemctl OR kill -9)... I look in the "top program" and 
that 30 or so MB of ram is STILL being used.

Is there a way to fix this? Thanks.

Joe

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/bed549a6-54e8-4cb7-87bc-9028d02a932b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Nodejs express calling function.

2017-05-19 Thread amir . navid
Hi, there is this following code which I'd like to bring the request part 
out of "app.post", store it in a separate file and call it whenever needed.

I have tried the export method but I was keep getting the undefined for 
"req" and "res".

app.post('/hook', function (req, res) {
url = "https://MY_URL;,


// ( request part )
// I'd like to store following to a separate file 
// and call it from main file whenever needed.


request({url : url, headers : {"Authorization" : auth}},
function (error, response, body) {
parseString(body, function (err, result) {
try {
return res.json({
"SOME_JSON": "JSON"
});
} catch (err) {
console.error("no request!", err);
}
});
});
// end request
});


a help on this would be greatly appreciated.


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8802d48f-da79-44b6-af9c-5a95b492443e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.