Sunday, 23 April 2017

node server not get any http request on local net

I run node server locally on my computer (windows 7) and my firewall not running and my server not receive any request from any another computer that in the same network.

what i need to do ?

please help



via noam aghai

How to play video from link in html5 using angularjs

How i can run youtube in my own web. As link is got from database using node server and using Angularjs i am showing link and play youtube video, but it does not work. when i place output to src attribute like src=" this does not work, but with proper youtube link, it works fine.

link type : string

HTML tags angularjs controller



via Saqi

Express4 routing issue

I am currently using router.param() to load a resource instance when a specific param is detected:

table.route.js

import express from 'express';
import validate from 'express-validation';
import paramValidation from '../../../config/param-validation';
import tableCtrl from '../controllers/table.controller';
const router = express.Router(); 
router.route('/:tableId')
   /** GET /api/tables/:tableId - Get table */
  .get(tableCtrl.get)

  /** PUT /api/tables/:tableId - Update table */
  .put(validate(paramValidation.updateTable), tableCtrl.update)

  /** DELETE /api/tables/:tableId - Delete table */
  .delete(tableCtrl.remove);

/** Load table when API with tableId route parameter is hit */
router.param('tableId', tableCtrl.load);

export default router;

table.controller.js

import Table from '../../models/table.model';
function load(req, res, next, id) {
  Table.get(id)
    .then((table) => {
      req.table = table; // eslint-disable-line no-param-reassign
      return next();
    })
    .catch(e => next(e));
}

function get(req, res) {
  return res.json(req.table);
}
export default { load, get, ... };

This work well... however, I need to add another route to get only the meta object from the Table model

table.model.js

const TableSchema = new mongoose.Schema({
  meta: {...},
  columns: [{ ....}]
});

So I can add the following route with 'meta' as a path parameter

router.route('/:tableId/meta')
   /** GET /api/tables/:tableId - Get table */
  .get(tableCtrl.get)

As 'meta' is a path parameter after the :tableId param, how can I avoid executing the tableCtrl.load function, and rather executing another one like tableCtrl.loadMeta

router.param('tableId', tableCtrl.load); router.param('tableId/meta', tableCtrl.loadMeta); <= this is wrong of course

thanks for your feedback



via erwin

Error when using Typescript MongoDb Typings (Cannot find namespace)

i am trying to use mongodb typings which i installed via

npm install @types/mongodb -D

now i want to use the types in a function like that

export default async function insertOne(collection:any, data:any):Promise<MongoClient.Collection.InsertOneWriteOpResult> {
  let db = await state.db
  let col = await db.collection(collection)
  let result = await col.insertOne(data)
  return result
}

i am specifically interested in the Type of InsertOneWriteOpResult. but i am getting the typescript compiler error:

src/utils/mongodb/collection/insert-one.ts|5 col 17 error| Cannot find namespace 'MongoClient'.

i referenced the typings file in my typings.d.ts

/// <reference path="./../node_modules/@types/mongodb/index.d.ts" />

So my question is, which namespace do i have to use to let typescript check against InsertOptionsWriteOpResult?



via divramod

People ask for the @ character in import form '@' in nodejs or vuejs

What is it ?

If you have to write: Import Login from '../../views/auth/Login'

Then write like this it also runs: Import Login from '@/views/auth/login'

Please someone can explain...



via Tran Hoang Hiep

Sharing custom code between two NodeJS microservices

I am creating web app and micorservice for that app, and both need to have same DB model created with Sequelize. What is approach for handling this task with NodeJS?

I am thinking about creating separate module of my DB models and save it in private git and add this private git to my web app and microservice as npm dependency.

But I am wondering is it right approach or what is right way to separate shared private module between few microservices, in my case it is DB models? Should I go with DRY or not?

Thanks in advance!



via Aren Hovsepyan

Cannot GET / error in nodeJS

I am developing a simple MEAN stack application. I am using angular routing to redirect to a page based on the Id of the item clicked like this:

   when('/story/:id', {
      template: '<news-detail></news-detail>'
   })

When an item is clicked it should go to a page like this : http://localhost:3002/story/58fbcf765865db1d8da94b41

but on that page I get a "Cannot GET /story/58fbcf765865db1d8da94b41" node error.

from back end I have tried this:

 app.get('/story/:id', function(req, res){
   if(req){
    var id = req.params.id;
    PostProfile.News.findById(id, function(err, item){
        if(item){
            console.log("found")
            res.send(item)
        }
    })
  }
})

This solution just displays some raw json on the page

 {"_id":"58fbc2834f675c1cdb7dc628","title": .....

What is the walk around for this and how can I use angular to make the request by id without going through nodejs first.

thanks alot.



via charles okojie