Posts

Uplaod to Firebase Storage from Node Express REST

Image
I need to upload user profile picture from mobile device trogh rest API to Firebase storage .Finally I go the follwing articale wich really guide me .  https://mzmuse.com/blog/how-to-upload-to-firebase-storage-in-node In order to upload the file from Express REST I used connect-busboy and fs node modules . Route file   router.post('/api/user-pic/profile-type/:type', ProfilePicController.setProfile); Controller File    exports.setProfile = function(req, res, next) {                     var fstream;                     req.pipe(req.busboy);                     req.busboy.on('file', function (fieldname, file, filename) {                                           console.log("Uploading: " + filename);                         fstream = fs.createWriteStream(__dirname + '/files/' + filename);                               file.pipe(fstream);                         const filePath = __dirname + '/files/' + filename;  

Node Express REST API Document while coding

I have used apidoc in my  Node Express REST Project . It works like charm and cpable to handle document versioning. APIDOC Inline Documentation for RESTful web APIs http://apidocjs.com/#param-api-description 1.npm install apidoc - g 2. /** * @api {get} /tasks/:id Find a task * @apiGroup Tasks * @apiDescription User login + register user if user login for the frist time. * @apiParam {id} id Task id * @apiSuccess {Number} id Task id * @apiSuccess {String} title Task title * @apiSuccess {Boolean} done Task is done? * @apiSuccess {Date} updated_at Update's date * @apiSuccess {Date} created_at Register's date * @apiSuccessExample {json} Success * HTTP/1.1 200 OK * { * "id": 1, * "title": "Study", * "done": false * "updated_at": "2016-02-10T15:46:51.778Z", * "created_at": "2016-02-10T15:46:51.778Z" * } * @apiErrorExample {json} Task not f

ENOENT: no such file or directory, rename : node_modules/async

Image
I have gone trough follwing error ,when I was updating npm. npm ERR! path /Users/interlectivethree/firebase/fetchme/server/node_modules/winston/node_modules/async npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall rename npm ERR! enoent ENOENT: no such file or directory, rename '/Users/interlectivethree/firebase/fetchme/server/node_modules/winston/node_modules/async' -> '/Users/interlectivethree/firebase/fetchme/server/node_modules/winston/node_modules/.async.DELETE' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR!     /Users/interlectivethree/.npm/_logs/2017-07-07T14_17_29_016Z-debug.log I have done sevarel things like package wise unstall and install ,package relocating .But no success .But I think compleate unstall and reinstall is the best option and follwing commands used. npm uninstall ` ls - 1 node_modules | tr '/\n' ' &#

Docker Dev Environment with Nodemon and Mongo DB

Image
1 Install Docker  Community ediction and Composer https://blog.codeship.com/using-docker-compose-for-nodejs-development/ 2 . Sampe application resides in server folder which have the package.json file ensure package.json  has script.  "start": "nodemon -L index.js" ensure nodemon.json exhist 3. touch Dockerfile. FROM node:8.1.0-alpine RUN mkdir /server RUN npm install nodemon -g ADD ./server /server WORKDIR /server RUN npm install #ADD server/nodemon.json /server/nodemon.json EXPOSE 3000 CMD npm start 5. docker-compose build 6.touch docker-compose.yml version: '2' services:   web:     build: .     volumes:     - "./server:/server"     ports:       - "3000:3000"     links:       - mongo   mongo:     image: mongo:3.4.4     container_name: mongo     ports:       - "27017:27017" 7.docker-compse up. application runs in localhost port 3000

Firebase Promises

Image
 Firebase Nodejs requests are Asyncronus .Which means, in the follwing code block I need to check order users exhist before set user. But the user order insert fucntion written second will fire before validation finished .Developer need to careful on this when firebase adopted.     for(var user in users) {                                              f irebase.database().ref("users"); users.once("value", function(snapshot) {                                      var temp= snapshot.exists();                                                             if (temp) {                                           var temp= on_exhist_checked(snapshot);                                              }                          });                      } function on_exhist_checked(snapshot) {                             var  temp= f irebase.database(). child(snapshot.key).child('orders').set({                                   key: true                

Firebase REST API auth - access token

I have to use Firebase Database and server a REST API .I need to allow the REST API call only for authenticated users from the same freebase. According to Documentation on REST API Save data > Auth Section I able to successfully access the Database using database secret . https://firebase.google.com/docs/database/rest/save-data But I could not successfully retrieve the data using access token of authenticated user . https://<<removed-my-project-id>>.firebaseio.com/users.json?access_token=ya29.GlxuBLxJ6R2uNYJ7SXnMhe7Inqw94ShGeZ7MTBmyxYUI2cLDCXJcPAfbo1_uKLjUhfPX3uQw_ElBjIVwu73caeKJfBAh87GGRWZx2JiSwuIZybAmtVXyFyqaeYbAJQ Reffering confusing document again I pass the URL as fallows using the idtoken.(currentUser.getIdToken taken from cleint side) https:// <<my-project-id>> .firebaseio.com/users.json?auth=eyJhbGciOiJSUzI1NiIsImtpZCI6IjBkNWNlYjA1ODA2ODk3OTM3ZTAxNGFjMDNkYWZkODQyMzM4ZjBlNmQifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZmV0Y2htZS1

Custom Email template for Laravel Password Reset

Image
Today I got new task with laravel , since I  have forget passwrod reset scenario. It works but not using the UIs of our theme.Scpecailly mail. However reset pasword section of the follwing helps me . http://miftyisbored.com/a-complete-laravel-5-3-tutorial-for-user-authentication-with-activation-email/ Mailtrap will help you. php artisan vendor:publish --tag=laravel-notifications     // email template php artisan make:notification ResetPassword.          .//edit temaplte parameters chage user class to call notification   public function sendPasswordResetNotification($token)     {         $this->notify(new ResetPassword($token));     } change ResetPassword in notification folder  eg : namespace App\Notifications; use Illuminate\Notifications\Notification; use Illuminate\Notifications\Messages\MailMessage; class PasswordResetNotification extends Notification  {     /**      * The password reset token.      *      * @var strin