How is it possible to return php values to a .js file?
I can’t use echo.
Example php class:
return $_GET['q']['email'];
That should be returned to script.js
I realize I could work with echo. Unfortunately, this is not possible in a .js file.
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
How is it possible to return php values to a .js file?
I can’t use echo.
Example php class:
return $_GET['q']['email'];
That should be returned to script.js
I realize I could work with echo. Unfortunately, this is not possible in a .js file.
I’ve created long time ago a spreadsheet with several scripts using Google Scripts, one of the primary functions was related with onEdit()
function, which worked perfectly until last week.
I’ve been reading some posts here to change the function from Simple trigger to Trigger, but didn’t work, as while Simple Trigger is considering the written code which only is enabled if a specific cell is enabled, but by modifying to Trigger, the options are onEdit
or OnChange
, and both are acting over any change in the entire spreadsheet.
My biggest issue here, is that this a highly costumed dynamic report, hence, this particular trigger is re-creating all the charts that are in the spreadsheet, so, every chart deleted or created is a trigger for this script under the Trigger option.
a fire base integration i want to send sms notification by using fire base but a something went wrong when i runnnig code
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyCasdW_wO9dXzW6ptdEipsMiK-Iq4KInZHb3Y",
authDomain: "jksawoasdrktasdasdest.firebaseapp.com",
projectId: "jksaasdworktasdasest",
storageBucket: "jksaworktest.appspot.com",
messagingSenderId: "584180342775",
appId: "1:584180342775:web:acf2b53ddf0e3feb47228a",
measurementId: "G-V670962YZC"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
window.onload = () => render();
function render() {
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
"sign-in-button",
{
size: "invisible",
callback: (response) => {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
},
}
);
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
"recaptcha-container"
);
}
**whrn irun this code i have a meesage saying ** error message “auth/argument-error”
I’ve 6 images and i want to make a room literally a room with 4 walls, roof and floor, can this be done using JavaScript? I googled it and found nothing useful so far
The result I get now gives me blank when that character is not there:
Code
const categories = catSubSheet.getRange(2, 1, catSubSheet.getLastRow() - 1, 3).getValues();
let categories1 = categories.filter(e => e[0] != '').map(function (e) { return e[0] });
let sheetsToProcess = [];
for (let a = 0; a < categories1.length; a++) {
sheetNames = categories1[a].substring(0, categories1[a].indexOf(" ("));
sheetsToProcess.push('BOQ ' + sheetNames)
}
Data
[
[GF HTG SHEET 1 (Drawing)],
[GF HTG SHEET 2 (Drawing)],
[GF DWS SHEET 1],
]
The result
Sheets to Process: BOQ GF HTG SHEET 1,BOQ GF HTG SHEET 2,BOQ
Expected Result
Sheets to Process: BOQ GF HTG SHEET 1,BOQ GF HTG SHEET 2,BOQ GF DWS SHEET 1
Apologies if there is already an answer for this, I’ve been unable to locate one that has worked for me.
I have defined a menu system for React where the information is stored in an array of objects. Each object has the posibility of having sub items (objects in another array) and I’m looking to filter the entire menu for values.
Menu Object
[
{
"key": "Dashboard",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"title": "Dashboard",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/",
"children": "Dashboard"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Clients",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Clients",
"submenus": [
{
"key": "Clients.Add",
"title": "Create Client",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Clients/create",
"children": "Create Client"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Clients.List",
"title": "List Clients",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Clients/",
"children": "List Clients"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Clients.Search",
"title": "Search Clients",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Clients/search",
"children": "Search Clients"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"key": "Contractors",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Contractors",
"submenus": [
{
"key": "Contractors.Add",
"title": "Create Contractor",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Contractors/create",
"children": "Create Contractor"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Contractors.List",
"title": "List Contractors",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Contractors/",
"children": "List Contractors"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Contractors.Search",
"title": "Search Contractors",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Contractors/search",
"children": "Search Contractors"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"key": "Jobs",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Jobs",
"submenus": [
{
"key": "Jobs.Add",
"title": "Create Job",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Jobs/create",
"children": "Create Job"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Jobs.List",
"title": "List Jobs",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Jobs/",
"children": "List Jobs"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Jobs.Search",
"title": "Search Jobs",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Jobs/search",
"children": "Search Jobs"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"isDivider": true
},
{
"key": "Config",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Configuration",
"submenus": [
{
"key": "Config.Category.Add",
"title": "Create Category",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Category/create",
"children": "Create Category"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Category.List",
"title": "List Categories",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Category/",
"children": "List Categories"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Specialist.Add",
"title": "Create Specialist",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Specialist/create",
"children": "Create Specialist"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Specialist.List",
"title": "List Specialists",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Specialist/",
"children": "List Specialists"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Status.Add",
"title": "Create Status",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Status/create",
"children": "Create Status"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Status.List",
"title": "List Statuses",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Status/",
"children": "List Statuses"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"key": "UserManagement",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "User Management",
"submenus": [
{
"key": "UserManagement.Add",
"title": "Create User",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/UserManagement/create",
"children": "Create User"
},
"_owner": null,
"_store": {}
}
},
{
"key": "UserManagement.List",
"title": "List Users",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/UserManagement/",
"children": "List Users"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"isDivider": true
},
{
"key": "LockScreen",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"title": "Lock Screen",
"component": "Lock Screen"
}
]
So if I were to filter this on title for the value “list” it should return back
[
{
"key": "Clients",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Clients",
"submenus": [
{
"key": "Clients.List",
"title": "List Clients",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Clients/",
"children": "List Clients"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"key": "Contractors",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Contractors",
"submenus": [
{
"key": "Contractors.List",
"title": "List Contractors",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Contractors/",
"children": "List Contractors"
},
"_owner": null,
"_store": {}
}
},
]
},
{
"key": "Jobs",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Jobs",
"submenus": [
{
"key": "Jobs.List",
"title": "List Jobs",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Jobs/",
"children": "List Jobs"
},
"_owner": null,
"_store": {}
}
},
]
},
{
"key": "Config",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "Configuration",
"submenus": [
{
"key": "Config.Category.List",
"title": "List Categories",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Category/",
"children": "List Categories"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Specialist.List",
"title": "List Specialists",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Specialist/",
"children": "List Specialists"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Status.List",
"title": "List Statuses",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Status/",
"children": "List Statuses"
},
"_owner": null,
"_store": {}
}
}
]
},
{
"key": "UserManagement",
"icon": {
"type": {},
"key": null,
"ref": null,
"props": {},
"_owner": null,
"_store": {}
},
"isSubMenu": true,
"title": "User Management",
"submenus": [
{
"key": "UserManagement.List",
"title": "List Users",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/UserManagement/",
"children": "List Users"
},
"_owner": null,
"_store": {}
}
}
]
}
]
Or it should return back
[
{
"key": "Clients.List",
"title": "List Clients",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Clients/",
"children": "List Clients"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Contractors.List",
"title": "List Contractors",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Contractors/",
"children": "List Contractors"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Jobs.List",
"title": "List Jobs",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Jobs/",
"children": "List Jobs"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Category.List",
"title": "List Categories",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Category/",
"children": "List Categories"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Specialist.List",
"title": "List Specialists",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Specialist/",
"children": "List Specialists"
},
"_owner": null,
"_store": {}
}
},
{
"key": "Config.Status.List",
"title": "List Statuses",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/Config/Status/",
"children": "List Statuses"
},
"_owner": null,
"_store": {}
}
},
{
"key": "UserManagement.List",
"title": "List Users",
"component": {
"type": {},
"key": null,
"ref": null,
"props": {
"to": "/admin/UserManagement/",
"children": "List Users"
},
"_owner": null,
"_store": {}
}
}
]
At present I have the following which works for the 1st level objects, but the sub menu’s all get returned:
const MenuSearch = (value) => {
const SearchTerm = value.toLowerCase();
console.log(SearchTerm, MenuItems);
if (!value || value.length < 1){
// show all menu items
SetMenuItemsFiltered(MenuItems);
} else {
let temp = [...MenuItems];
SetMenuItemsFiltered(temp.filter((MenuItem) => {
if (!MenuItem.isSubMenu && !MenuItem.isDivider){
return MenuItem.title.toLowerCase().includes(SearchTerm);
} else if (MenuItem.isSubMenu){
return MenuItem.submenus.filter((SubMenuItem) => {
const SubMenuItemLabel = SubMenuItem.title.toLowerCase();
console.log(SubMenuItemLabel, SearchTerm, SubMenuItemLabel.includes(SearchTerm))
return SubMenuItemLabel.includes(SearchTerm.toLowerCase());
})
}
}));
}
}
I want G to stick to the bottom of it’s parent. (G to the bottom of the white background).
body {
position: relative;
background: #ccc;
font-size: 2em;
padding: 3em;
}
.staff {
display: flex;
padding: 1em;
background: white;
width: 100%;
position: absolute;
top: 50%;
left: 0;
}
.staff span {
position: absolute;
bottom: 0;
font-size: 1.008em;
}
.clef {
background: pink;
font-size: 0.25em;
vertical-align: 'bottom';
}
<div class='staff'>
<span class='clef'>G</span>
</div>
I also tried display: flex; align-items: flex-end;
but didn’t work
I created a fresh Next.js project and followed the Uniswap Widget guideline.
// create next app
npx create-next-app@latest
// add Uniswap widget dependency
yarn add @uniswap/widgets
// add Uniswap widget code
<div className="Uniswap">
<SwapWidget
provider={provider}
jsonRpcEndpoint={jsonRpcEndpoint} />
</div>
However, I get this error suggesting I should change React or Uniswap code to make it compatible with Next.js setup.
Is there anyway I can make this work without changing React or Uniswap libraries, as suggested by the error message?
error - Error [ERR_REQUIRE_ESM]: require() of ES Module /home/pomatti/pjs/uniswap/uniswap-widget/node_modules/@uniswap/widgets/node_modules/@web3-react/core/dist/cjs/index.js from /home/pomatti/pjs/uniswap/uniswap-widget/node_modules/@uniswap/widgets/dist/widgets.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/pomatti/pjs/uniswap/uniswap-widget/node_modules/@uniswap/widgets/node_modules/@web3-react/core/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
I’m Using Jquery DataTable and I’m working on RTL Version, every thing is OK but when I want to export on PDF every Arabic Letters change to [], Please help me..
$("#table_id").DataTable({
dom: "Bfrtip",
buttons: ["excel", "pdf", "print"],
searching: false,
paging: false,
});
it works for export to excel and print but the issue is only in PDF.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module ‘../build/Release/canvas.node’
Require stack:
Node.js v17.6.0
turcuoctavian@Turcus-MacBook-Pro hashlips_art_engine % yarn index.js
yarn run v1.22.17
warning ../../../package.json: No license field
error Command “index.js” not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
turcuoctavian@Turcus-MacBook-Pro hashlips_art_engine % npm instal
l canvas
npm notice Beginning October 4, 2021, all connections to the npm registry – including for package installation – must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry – including for package installation – must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm ERR! code 1
npm ERR! path /Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install –fallback-to-build
npm ERR! Failed to execute ‘/Users/turcuoctavian/.nvm/versions/node/v17.6.0/bin/node /Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure –fallback-to-build –module=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release/canvas.node –module_name=canvas –module_path=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release –napi_version=8 –node_abi_napi=napi –napi_build_version=0 –node_napi_label=node-v102’ (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using [email protected]
npm ERR! node-pre-gyp info using [email protected] | darwin | arm64
npm ERR! node-pre-gyp info check checked for “/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release/canvas.node” (not found)
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.9.0/canvas-v2.9.0-node-v102-darwin-unknown-arm64.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.9.0/canvas-v2.9.0-node-v102-darwin-unknown-arm64.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v102 ABI, unknown) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.9.0/canvas-v2.9.0-node-v102-darwin-unknown-arm64.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info ok
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.8.9 found at “/Library/Developer/CommandLineTools/usr/bin/python3”
npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args ‘/Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py’,
npm ERR! gyp info spawn args ‘binding.gyp’,
npm ERR! gyp info spawn args ‘-f’,
npm ERR! gyp info spawn args ‘make’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/config.gypi’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘/Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi’,
npm ERR! gyp info spawn args ‘-I’,
npm ERR! gyp info spawn args ‘/Users/turcuoctavian/Library/Caches/node-gyp/17.6.0/include/node/common.gypi’,
npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’,
npm ERR! gyp info spawn args ‘-Dvisibility=default’,
npm ERR! gyp info spawn args ‘-Dnode_root_dir=/Users/turcuoctavian/Library/Caches/node-gyp/17.6.0’,
npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=/Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp’,
npm ERR! gyp info spawn args ‘-Dnode_lib_file=/Users/turcuoctavian/Library/Caches/node-gyp/17.6.0/<(target_arch)/node.lib’,
npm ERR! gyp info spawn args ‘-Dmodule_root_dir=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas’,
npm ERR! gyp info spawn args ‘-Dnode_engine=v8’,
npm ERR! gyp info spawn args ‘–depth=.’,
npm ERR! gyp info spawn args ‘–no-parallel’,
npm ERR! gyp info spawn args ‘–generator-output’,
npm ERR! gyp info spawn args ‘build’,
npm ERR! gyp info spawn args ‘-Goutput_dir=.’
npm ERR! gyp info spawn args ]
npm ERR! /bin/sh: pkg-config: command not found
npm ERR! gyp: Call to ‘pkg-config pixman-1 –libs’ returned exit status 127 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: gyp
failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:259:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 21.3.0
npm ERR! gyp ERR! command “/Users/turcuoctavian/.nvm/versions/node/v17.6.0/bin/node” “/Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “configure” “–fallback-to-build” “–module=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release/canvas.node” “–module_name=canvas” “–module_path=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release” “–napi_version=8” “–node_abi_napi=napi” “–napi_build_version=0” “–node_napi_label=node-v102”
npm ERR! gyp ERR! cwd /Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas
npm ERR! gyp ERR! node -v v17.6.0
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok
npm ERR! node-pre-gyp ERR! build error
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute ‘/Users/turcuoctavian/.nvm/versions/node/v17.6.0/bin/node /Users/turcuoctavian/.nvm/versions/node/v17.6.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure –fallback-to-build –module=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release/canvas.node –module_name=canvas –module_path=/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas/build/Release –napi_version=8 –node_abi_napi=napi –napi_build_version=0 –node_napi_label=node-v102’ (1)
npm ERR! node-pre-gyp ERR! stack at ChildProcess. (/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1090:16)
npm ERR! node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! node-pre-gyp ERR! System Darwin 21.3.0
npm ERR! node-pre-gyp ERR! command “/Users/turcuoctavian/.nvm/versions/node/v17.6.0/bin/node” “/Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/.bin/node-pre-gyp” “install” “–fallback-to-build”
npm ERR! node-pre-gyp ERR! cwd /Users/turcuoctavian/Desktop/NFT generator/hashlips_art_engine/node_modules/canvas
npm ERR! node-pre-gyp ERR! node -v v17.6.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.6
npm ERR! node-pre-gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/turcuoctavian/.npm/_logs/2022-02-26T11_41_40_833Z-debug-0.log
turcuoctavian@Turcus-MacBook-Pro hashlips_art_engine % npm index.js
Unknown command: “index.js”
I am facing an error with node/express. I am assuming the issue is with my asynchronous code design.
Output:
Success in container
Expected Output:
Success in container..
Success in Uploading…
Error: (node:18364) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Code:
const express = require("express");
const multer = require("multer");
const AuthReq = require("../middleWare/AuthReq");
require("dotenv").config();
const Azure_Storage_Connection_String = process.env.Azure_Connection_String;
const { BlobServiceClient } = require("@azure/storage-blob");
const Router = express.Router();
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads");
},
filename: function (req, file, cb) {
cb(null, Date.now() + "-" + file.originalname);
},
});
const upload = multer({ storage: storage });
Router.post("/profile", AuthReq, upload.single("profile"), async (req, res) => {
const file = req.file;
const blobServiceClient = BlobServiceClient.fromConnectionString(
Azure_Storage_Connection_String
);
const containerName = req.user._id;
const ContainerClient = blobServiceClient.getContainerClient(containerName);
try {
const containerResponse = await ContainerClient.create();
} catch (err) {
return res.status(400).send("Error while sending image");
}
res.send("Success in container");
const contentType = file.mimetype;
const filePath = file.path;
const blobName = file.filename + contentType;
const blockBlobClient = ContainerClient.getBlockBlobClient(blobName);
try {
const uploadBlobResponse = await blockBlobClient.uploadFile(filePath);
} catch (err) {
return res.status(400).send("Error while sending image");
}
res.send("Success in Uploading...");
});
module.exports = Router;
i want to show “favorites” item in my favorites component. but since i can’t pass postList component to favorites component i don’t know how to do it.
basically this is what i get from this coding. but i want to show favorite items in another page/component:
Home.js
import React, { useState, useEffect } from "react";
import { getDocs, collection, deleteDoc, doc } from "firebase/firestore";
import { db, auth } from "../../firebase";
import { Link } from "react-router-dom";
import Sidebar from "../Sidebar/Sidebar";
import "./Home.css";
import PostList from "./PostList";
const Home = ({ isAuth, setIsAuth }) => {
const [postLists, setPostList] = useState([]);
const postsCollectionRef = collection(db, "posts");
const [favorites, setFavorites] = useState(localStorage.getItem("dam"));
useEffect(() => {
const getPosts = async () => {
const data = await getDocs(postsCollectionRef);
setPostList(data.docs.map((doc) => ({ ...doc.data(), id: doc.id })));
};
getPosts();
}, []);
useEffect(() => {
const localData = localStorage.getItem("dam") ?? [];
setFavorites(localData);
}, [setFavorites]);
const addFavorite = (favorite) => {
setFavorites((prevfavorites) => [...prevfavorites, favorite]);
localStorage.setItem("dam", JSON.stringify(favorites));
};
return (
<div className="containers">
<div className="sidebar">
<Sidebar isAuth={isAuth} setIsAuth={setIsAuth} />
<div className="centered">
<div className="bordered">
<button id="ado">
<Link to="/createpost">+ Add API</Link>
</button>
</div>
<div className="new-container">
{postLists?.map((post) => {
return (
<>
<PostList
post={post}
addFavorite={addFavorite}
key={post.id}
/>
</>
);
})}
</div>
</div>
<div className="another">
<h2>FAVORITE ITEMS</h2>
{postLists
.filter((post) => favorites.includes(post.id))
.map((post) => (
<PostList post={post} addFavorite={addFavorite} key={post.id} />
))}
</div>
</div>
</div>
);
};
export default Home;
PostList.js
import React from "react";
const PostList = ({ post, addFavorite }) => {
const { linkin, title, imageURL, photoURL, name, id } = post;
return (
<>
<div>
<div className="post">
<div className="postimage">
<div className="del"></div>
<div className="images">
<a href={linkin}>
<p className="ss">{title}</p>
<img src={imageURL} id="img-photo" />
</a>
<div className="uploader">
<img src={photoURL} />
<p>by {name}</p>
</div>
{addFavorite && (
<div className="butons">
<button onClick={() => addFavorite(id)} id="favori">
+
</button>
</div>
)}
</div>
</div>
</div>
</div>
</>
);
};
export default PostList;
and a empty Favorites.js component.
Favorites.js
favorites here...
Every time I try to create an order via /api/order it gives me 400 (Bad request), there doesn’t seem to be a proper clear explanation anywhere on how to create records with relational fields, the only one I found close to what I needed was this:
So supposedly I should use an id or a list of ids depending on the type of relation, but it still gives me 400 Bad request with no explanation in the response.
My order content-type looks like this:
User is a Many-to-One relationship, so a user can have many orders, but there can only be one user per order, and products is One-to-Many, so an order can have many products
This is what my API call looks like:
await axios.post(
`${baseUrl}/api/orders`,
{
products: [9],
total: 320,
user: 42
}
);
The products and user ids are exactly the ones I have in the database and authentication is not the problem.
Please help me understand what I’m doing wrong and how I should be creating records with relational fields. Thanks
I would like to leave line trails at each of the corners of the rectangles. I have tried createGraphics to add an extra canvas where I want to leave the trails but it’s just doesn’t work.
I purposefully rotate the rectangle with cosine. My assignment forbids to use the rotate function.
I followed this tutorial: https://www.youtube.com/watch?v=TaluaAD9MKA
The Sketch:
Without createGraphics: https://editor.p5js.org/plaszlo/sketches/W6Bq6zAI3
With createGraphics: https://editor.p5js.org/plaszlo/sketches/WQhPN5e7F
Thank you
I was working on a Next js blog,
I have completed the frontend and I was making backend using the next js
./pages/api
I made a file
./pages/api/blogs.js
I made some json files in ./data
folder as dummy data
./data/hello.json
{
"title" : "This is hello",
"description" : "This is description",
"content" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto quasi error cumque iure tempore officiis quaerat rerum delectus hic reprehenderit. Iure, eveniet repudiandae. Consequuntur obcaecati eius sequi similique officia beatae quibusdam blanditiis."
}
I write this code in ./pages/api/blogs.js
import * as fs from 'fs'
export default function handler(req, res) {
fs.readFile("../../data/hello.json", (err,data)=>{
console.log(data)
})
res.status(200).json({"name" : "Shivam Bhai"})
}
but my server console is showing undefined.
how do I fix this problem?