Snippets Collections
var tracker = {};
var depth = 0;
var prevNode;
Array.from(document.querySelectorAll("*")).forEach(node => {
    if (!tracker[node.tagName]) tracker[node.tagName] = 1;
    else tracker[node.tagName]++;
    console.log("Node depth:", node.tagName, depth);
    if (node.parentNode != prevNode) depth++;
    prevNode = node;
});
console.log(tracker);
// 1. IMPORTACIONES
const express   =      require("express")
const app       =      express()
const hbs       =      require("hbs")     

const connectingDB  =   require('./config/db')


// 2. MIDDLEWARES
// ACTIVAR VARIABLES DE ENTORNO
require('dotenv').config()

// GESTIÓN DE BASE DE DATOS
connectingDB()

// ACTIVACIÓN DE LA CARPETA DE PUBLIC
app.use(express.static(__dirname + "/public"))

// ACTIVAR CARPETA DE VISTAS
app.set("views", __dirname + "views")

// ACTIVAR HANDLEBARS
app.set("view engine", "hbs")

// ACTIVAR RECEPCIÓN DE DATOS DE FORMULARIOS
app.use(express.urlencoded({ extended: true }))





// 3. RUTEO
app.use("/", require("./"))
//app.use("/users", require("./routes/users"))


// 4. SERVIDOR
app.listen(process.env.PORT, () => console.log(`Servidor activo en el puerto ${ process.env.PORT }`))
global $language;
$lang = $language->language;
$base_node = node_load(XXXXX);

$translations = translation_node_get_translations($base_node->tnid);
$translated_node = (isset($translations[$lang])?node_load($translations[$lang]->nid):$base_node);
// monsters.js
const express = require('express');
const monstersRouter = express.Router();
 
const monsters = {
  '1': {
    name: 'godzilla',
    age: 250000000
  },
  '2': {
    Name: 'manticore',
    age: 21
  }
}
 
monstersRouter.get('/:id', (req, res, next) => {
  const monster = monsters[req.params.id];
  if (monster) {
    res.send(monster);
  } else {
    res.status(404).send();
  }
});
 
module.exports = monstersRouter;



//// and
// main.js
const express = require('express');
const app = express();
const monstersRouter = require('./monsters.js');
 
app.use('/monsters', monstersRouter);
app.post('/expressions', (req, res, next) => {
  const receivedExpression = createElement('expressions', req.query);
  if (receivedExpression) {
    expressions.push(receivedExpression);
    res.status(201).send(receivedExpression);
  } else {
    res.status(400).send();
  }
});
app.delete('/expressions/:id',(req,res,next)=>{
      const eleIndex = getIndexById(req.params.id,expressions);
    if(eleIndex!==-1){
        expressions.splice(eleIndex,1);
        res.status(204).send(expressions[eleIndex]);
    }
    else{
        res.status(404).send();
    }
});
const monsters = { 
  hydra: { height: 3, age: 4 }, 
  dragon: { height: 200, age: 350 } 
};
// GET /monsters/hydra
app.get('/monsters/:name', (req, res, next) => {
  console.log(req.params)' // { name: 'hydra' }
  res.send(monsters[req.params.name]);
});
const monsters = [
  { type: 'werewolf' }, 
  { type: 'hydra' }, 
  { type: 'chupacabra' }
];
app.get('/monsters', (req, res, next) => {
  res.send(monsters);
});
const express = require('express');
const app = express();
const PORT = process.env.PORT || 4001;

// Invoke the app's `.listen()` method below:
app.listen(PORT,() => {
  console.log(`Server is listening on port ${PORT}`);
});
const http = require('http');
 
let requestListener = (request, response) => {
  response.writeHead(200, {'Content-Type': 'text/plain' });
  response.write('Hello World!\n');
  response.end();
};
 
const server = http.createServer(requestListener);
 
server.listen(3000);
const fs = require('fs')
 
const fileStream = fs.createWriteStream('output.txt');
 
fileStream.write('This is the first line!'); 
fileStream.write('This is the second line!');
fileStream.end();
const readline = require('readline');
const fs = require('fs');
 
const myInterface = readline.createInterface({
  input: fs.createReadStream('text.txt')
});
 
myInterface.on('line', (fileLine) => {
  console.log(`The line read: ${fileLine}`);
});
const fs = require('fs');
 
let readDataCallback = (err, data) => {
  if (err) {
    console.log(`Something went wrong: ${err}`);
  } else {
    console.log(`Provided file contained: ${data}`);
  }
};
 
fs.readFile('./file.txt', 'utf-8', readDataCallback);
function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

await timeout(1000); // pauses execution for 1000ms
star

Tue May 03 2022 15:17:05 GMT+0000 (UTC) https://stackoverflow.com/questions/33903929/iterate-through-html-dom-and-get-depth

#node #depth
star

Fri Sep 03 2021 09:25:59 GMT+0000 (UTC) https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_get_translations/7.x

#drupal #drupal7 #node #translation #languages
star

Tue Aug 31 2021 08:11:26 GMT+0000 (UTC)

#node
star

Tue Aug 31 2021 07:35:20 GMT+0000 (UTC)

#node
star

Tue Aug 31 2021 05:43:33 GMT+0000 (UTC)

#node
star

Tue Aug 31 2021 05:37:21 GMT+0000 (UTC)

#node
star

Tue Aug 31 2021 02:35:43 GMT+0000 (UTC)

#node
star

Tue Aug 31 2021 02:07:50 GMT+0000 (UTC)

#node #filesystem
star

Tue Aug 31 2021 01:55:22 GMT+0000 (UTC)

#node #filesystem
star

Mon Mar 29 2021 17:30:16 GMT+0000 (UTC)

#javascript #node #sleep
star

Sat Mar 06 2021 18:58:29 GMT+0000 (UTC) https://stackoverflow.com/questions/23691194/node-express-file-upload

#node #busboy

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension