Category: Javascript

  • How to Run Node.Js Application as Different User?

    In your .env file add USER=www-data Note: I have choose to run node as the user www-data you can choose any other appropriate one. Now Run $ npm i userid –save At the top of your app.js or index.js file add const userid = require(‘userid’);const user = process.env.USER;const uid = parseInt(user), 10);// Set server’s uid […]

  • How to Convert GET URL Structure to Array and Reverse

    [js] function URLToArray(url) { var request = {}; var pairs = url.substring(url.indexOf(‘?’) + 1).split(‘&’); for (var i = 0; i < pairs.length; i++) { var pair = pairs[i].split(‘=’); request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); } return request; } function ArrayToURL(array) { var pairs = []; for (var key in array) if (array.hasOwnProperty(key)) pairs.push(encodeURIComponent(key) + ‘=’ + encodeURIComponent(array[key])); return […]

  • How to Check on jQuery if a DOM Element Exists

    Below is how you will able to know if a dom element exists 🙂 Quite simple! [javascript] if($("#dom").length > 0){ //dom exists }else{ //dom doesn’t exists } [/javascript]