GetById Node JS


Hola, buenas noches. Estoy desarrollando una API mediante node JS en la cual mi finalidad es obtener los discos seleccionados de acuerdo al artista en específico.

Sucede que tengo mi siguiente JSON y me gustaría poder obtener un nuevo json de acuerdo al Id de un Artista, por ejemplo, si deseo buscar el artista número uno el tercer resultado debería de omitirse y así sucesivamente. Estoy utilizando nodeJS y quiero consumirlo a manera de GET pasando por parámetro en la URL el Id a buscar. Muchas gracias

    [   {     "id": "1",     "nombre": "Favourite Worst Nightmare",     "year": "2007",     "imagen": "https://is5-ssl.mzstatic.com/image/thumb/Music/6e/6e/d4/mzi.hozudery.jpg/600x600bf.png",     "idArtista": "1",     "tracklist": [       {         "song": "Brianstorm",         "link": "https://www.youtube.com/watch?v=uR3bNrIg9eE"       },       {         "song": "Teddy Picker",         "link": "https://www.youtube.com/watch?v=hl2lxaNjQOI"       },       {         "song": "505",         "link": "https://www.youtube.com/watch?v=nNZCXzbj6Ds"       }     ]   },   {     "id": "2",     "nombre": "Whatever People Say I Am, That's What I'm Not",     "year": "2006",     "imagen": "https://is5-ssl.mzstatic.com/image/thumb/Features/9a/68/e6/dj.npwkgmai.jpg/600x600bf.png",     "idArtista": "1",     "tracklist": [       {         "song": "The View from the Afternoon",         "link": "https://www.youtube.com/watch?v=S_N9jJwN1gE"       },       {         "song": "Dancing Shoes",         "link": "https://www.youtube.com/watch?v=GYnUb1xDQ74"       },       {         "song": "A Certain Romance",         "link": "https://www.youtube.com/watch?v=rQYLf2-vkC8"       }     ]   },   {     "id": "3",     "nombre": "Innespeaker",     "year": "2010",     "imagen": "https://media.pitchfork.com/photos/5929a9e913d197565213993e/1:1/w_600/7ea586f7.jpg",     "idArtista": "12",     "tracklist": [       {         "song": "It's Not Meant to Be",         "link": "https://www.youtube.com/watch?v=KeZt5IGJ1T8"       },       {         "song": "Alter Ego",         "link": "https://www.youtube.com/watch?v=iErjaKTX_3w"       },       {         "song": "Lucidity",         "link": "https://www.youtube.com/watch?v=qFe4lfueUdk"       }     ]   } ] 

YA LO RESOLVÍ, SALUDOS

  /*Get ById*/  router.get('/:id?',(req,res) =>{     const idArt = req.params;     const newTracks = _.where(tracks, {idArtista : idArt.id});     res.json(newTracks); });   module.exports = router; 

how to implemented a MyS database HA when the candidate node already is a multi-source replication node?

MySQL 5.7.21 Community Version.

  1. Our node have a MySQL instance base on multi-source replication from 5 replication source.
  2. but this node does not fit HA purpose with single point failure.
  3. when we try to build master-slave or dual master on it, it can not be done with reset master process.

how to implemented the HA on this kind of MySQL instance?

Node webapp not running under pm2, but works when ran alone

I have a very simple node.js webapp with the following code:

const express = require('express'); const bodyParser = require('body-parser');  const app = express(); app.use(bodyParser.json({}));  app.get('/', (req, res) => {     res.status(200).send('it works'); });  app.listen(4000); 

When I run it simply with node app.js, I can navigate to the URL and I see the “it works” message. However when I run it with pm2 start app.js, I get the success message [PM2] Spawning PM2 daemon with pm2_home=/home/pushduratech/.pm2, but the application is not actually running and I don’t see the test message at the URL anymore.

Server is running CentOS 7, and the latest versions of node, npm, and pm2.

Changing how Adding Existing Node (from another content type) works

I have a Drupal 8 site with two content types: Recipe and Ingredient, and I have Ingredient as an inline entity form of Recipe form.

So, when I am creating a new Recipe, I get this: enter image description here

My question is: can I change how Add Existing Node works to, instead of a button, it shows a select list with all the current posibilities?

Thank you in advance.

Changing how Adding Existing Node (from another content type) works

I have a Drupal 8 site with two content types: Recipe and Ingredient, and I have Ingredient as an inline entity form of Recipe form.

So, when I am creating a new Recipe, I get this: enter image description here

My question is: can I change how Add Existing Node works to, instead of a button, it shows a select list with all the current posibilities?

Thank you in advance.

Render Date Range on node template

I’m trying to render both start and end date on a node template in Drupal 8 from the Date range field from the content type. I’ve tried multiple ways to no avail.

— Only shows start date —

{{ kint(node.field_date_range.value ) }}   {% if node.field_date_range %} {{ node.field_date_range.value|date(format='l M j') }} {% endif %} 

After implementing hook_node_access, how to stop node from appearing in view?

In Drupal 8, I implemented a hook_node_access function in my module to control access for a certain role under certain conditions and it works fine.

However, all of that content type are still shown on a view when the user views it. This is expected behavior according to the documentation:

In node listings (lists of nodes generated from a select query, such as the default home page at path ‘node’, an RSS feed, a recent content block, etc.), … hook_node_access() is not called on each node for performance reasons and for proper functioning of the pager system. When adding a node listing to your module, be sure to use an entity query, which will add a tag of “node_access”. This will allow modules dealing with node access to ensure only nodes to which the user has access are retrieved, through the use of hook_query_TAG_alter(). See the Entity API topic for more information on entity queries.

(Link)

I understand why the view does not check each individual content, but I do not understand what this documentation is asking me to do to fix that. The documentation for hook_query_TAG_alter and on entity queries is not very helpful either.

How do I ensure that only items of this content type that the current user has view access to are shown in a view?

Send email to all users that are tagged with the same tag a node is when created

There is a lot of similar questions here but I am having a hard time wrapping my head around this.

I have a taxonomy term reference field called field_category. This field is available on user/*/edit and on node/add.

Category

  • 1
  • 2
  • 3

What I would like to do is send an email when a node is created that has the same taxonomy term(s) that a user has specified in their profile.

I have tried to wrap my head around using the rules and view_rules module but every configuration I have tried fails.

Can anyone provide me with some direction? Thanks!

Drupal 7.65

Rules: 7.x-2.12

Views Rules 7.x-1.0

Stale block verification at node level

It comes to my curiousity about how exactly the node A will mine block N+1 when he & node B generated block N (not in same time but) in a fairly close timeframe.

In many articles, it says that when 2 nodes (A&B) are generating the same height block at same time, it will cause a fork. This means some nodes will mine after A’s new block and others mine B’s. This is understood. However, it will take time when A’s new block sync to B. Let’s assume it takes 10 seconds to pass to B. In the middle of the sync (saying 5th or 6th second of total 10), B just generates the new block (with same height), and propagate it out before receiving A’s block. What will happen when B receives A’s block then?

I have 2 possible answers but not sure which one is correct, or neither. (assuming all TX/UTXO in the block has no issue)

ANSWER-1: B will discard B’s block, and accept A’s, because B block’s timestamp is older than A’s (make sense?)

ANSWER-2: when B broadcasts his new block, B by default accepts its own generated block (N+1) and immediately start to mine block N+2 upon that (at the time when B has not received A’s block yet.) Then B receives A’s block (N+1), in this case, B should keep A’s chain but still continue to mine at his N+2 block height.

Any advice?