I ran the node code on this site https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html by using:
node app
I get the following error:
TypeError: request.ref is not a function.
which corresponds to the following line:
sendNotificationToUser("username","new msg",function() {request.ref().remove();} );
This is my package.json file:
{
"name": "myApp",
"version": "1.0.1",
"description": "listen for addition of msgs",
"main": "app.js",
"scripts": {
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud app deploy"
},
"author": "my name",
"engines": {
"node": "~4.2"
},
"license": "ISC",
"dependencies": {
"firebase": "^3.2.1",
"request": "^2.74.0"
}
}
There are indeed some typos in the code. The actual version I run with uses this to remove the messages that have been sent:
requestSnapshot.ref.remove();
The entire listenForNotificationRequests method (in case I made any other edit mistakes while porting to the blog):
function listenForNotificationRequests() {
var requests = ref.child('notificationRequests');
requests.on('child_added', function(requestSnapshot) {
var request = requestSnapshot.val();
sendNotificationToUser(
request.username,
request.message,
function() {
requestSnapshot.ref.remove();
}
);
}, function(error) {
console.error(error);
});
};
Related
I tried to create a site in Vercel for my project (link), but for some reason it returned the following error:
Error: Runtime exited with error: exit status 1 Runtime.ExitError
ERROR Cannot find module 'dotenv' Require stack: -/var/task/index.js
ERROR Did you forget to add it to "dependencies" in package.json?
I tried to delete the first line of code from index.js, which requires the dotenv library, since I don't really need it in vercel, but it gives an error when importing express, so I want to know how to solve this problem.
Below is the code of package.json and vercel.json (for some reason I believe the error is in one of these files)
Package.json:
{
"name": "url_saver",
"version": "1.0.0",
"description": "A FCC project",
"main": "index.js",
"engines": {
"node": "14.x"
},
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "~4.18.1",
"mongoose": "~6.6.2",
"dotenv": "~16.0.3",
"dns": "~0.2.2",
"url": "~0.11.0",
"open": "~8.4.0"
},
"keywords": [
"node",
"express",
"freecodecamp",
"mongoose"
],
"license": "MIT",
"author": "Samuel Schlemper"
}
Vercel.json:
{
"version": 2,
"builds": [
{
"src": "./index.js",
"use": "#vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}
Link to full repository on github: https://github.com/Samuel-Schlemper-Schlemuel/Save_URL
I am facing the sqlite db issue in production mode.
Its working fine on using npm start (on normally run) but not working when i try to create release file for linux using electron-builder build --linux
my package.json file is as follows
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"dist": "electron-builder"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^13.1.0",
"electron-packager": "^15.2.0"
},
"build": {
"appId": "pkg.dmo.com",
"productName": "sample",
"copyright": "Copyright",
"mac": {
"target": [
"zip"
],
"publish": [
"github"
]
},
"win": {
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage",
"tar.gz"
]
},
"dmg": {
"icon": "build/icon.icns"
}
},
"dependencies": {
"jquery": "^3.6.0",
"sqlite3": "^5.0.2"
}
}
and my sqlite code is as follows:
let $ = (jQuery = require("jquery"));
const sqlite3 = require("sqlite3").verbose();
const path = require('path')
const dbPath = path.join(__dirname, 'testdb.db');
$( document ).ready(function() {
let db = new sqlite3.Database(
dbPath,
sqlite3.OPEN_READWRITE,
(err) => {
if (err) {
console.error(err.message);
}
}
);
db.each("SELECT * FROM Mouse", [], function (err, row) {
console.log("helli");
if (err) {
console.log(err);
return console.error(err.message);
}
console.log("mouse row is =>", row);
});
});
i have tried
var db = new sqlite3.Database( path.resolve(__dirname, 'testdb.db') );
and
var db = new sqlite3.Database( path.join(__dirname,
'testdb.db').replace('/app.asar', '') );
still getting same error in exe but working on local(when npm start)
Have you ever had this issue:
I was working on my app in development, and everything works fine, but when I created the executable and try to click on my button throw this error:
This the code that is executed when I press my button:
const { exec } = require("child_process");
let myBtn = document.getElementById('my-btn');
myBtn.addEventListener('click', (e) => {
e.preventDefault();
exec("node index.js", (error, data, getter) => {
if(error){
console.log("error",error.message);
return;
}
if(getter){
console.log("data",data);
return;
}
console.log("data",data);
});
});
This the error:
Not recognize the module node and my file index.js
error Command failed: node index.js
internal/modules/cjs/loader.js:1068
throw err;
^
Error: Cannot find module '/home/myUser/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
at Function.Module._load (internal/modules/cjs/loader.js:911:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is my package.json
{
"name": "app",
"version": "1.0.0",
"description": "description",
"main": "main.js",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"puppeteer": "^9.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "^12.0.5"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
}
}
I have a file my-script.js that only returns this:
console.log('Hi I'm working')
When I type in shell only
node my-script.js
This works successfully.
But I'd like it to work too when I typed in just this:
npm start
How to make it work?
Because it is generating an error message:
Line: 1 Error: console is undefined Code: 800A1391 Source: Microsoft
JScript runtime error
I have a package.json file that points to this file to be the start but this is not resolving.
Here is my package.json file:
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}
Use node in start script
{
"name": "my-app",
"version": "1.0.0",
"main": "my-script.js",
"scripts": {
"start": "node my-script.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"webpack": "^4.41.2"
},
"description": ""
}
When i put 'gulp hello' in cmd i got this error 800a138f javascript object expected error
This is my package.json file
`{
"name": "goes",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node gulp.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1"
}
}`
This is gulp.js
`var gulp = require('gulp');
gulp.task('hello', function() {
console.log('Hello Zell');
});`