I have Meteor v1 installed and GraphicsMagick installed.
When the app starts, the console tells me "GraphicsMagick found"
However when I try to follow these simple instructions: (https://github.com/aheckmann/gm/blob/master/README.md)
var fs = require('fs')
, gm = require('./gm');
// resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
.options({imageMagick: true})
.resize(240, 240)
...
I get "undefined is not a function" (referring to require('gm'))
Am I doing something wrong? How can I use GM in Meteor?
Related
im trying use the chrome driver, with selenium in the firebase cloud functions.
while deploying the index.js file on to a local host, using the terminal cmd
'firebase serve --only functions' from the functions folder(which has the chromedriver file, every thing work like in supposed to, im getting a response.
But,
when I deploying the index.js file to the firebase real servers using the
'firebase deploy --only functions' ,
and then trigger the function from my app, or from a url,
im getting an error in the firebase cloud functions logs telling me
'Function execution took 1774 ms, finished with status: 'crash' '
so since there were not details about what was causing this 'crash' I uses the consoled.log() function, and printed each line that was executed successfully.
this lead me into the line of
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless().windowSize(screen)).build();
its seems like in the firebase cloud function I can't for some reason create a chrome driver successfully , although in the local host version, it's working as expected.
here the full code of the function:
exports.initializedChromeDriver = functions.https.onRequest((request, response) => {
async function start_chrome_driver() {
functions.logger.info('Hello logs!', {structuredData: true});
console.log("did enter the function")
const dic = {};
const google_site = "https://www.gooogle.com";
const { WebDriver } = require('selenium-webdriver');
const {Builder, By} = require('selenium-webdriver');
console.log("did creat WebDriver,Builder, By, constans")
const chrome = require('selenium-webdriver/chrome');
console.log("chrome constans was created")
const screen = {
width: 1024,
height: 1024
};
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless().windowSize(screen)).build();
console.log("driver was set");
await driver.get(google_site);
console.log("succ loading google");
return "succ loading google"
}
const p = start_chrome_driver().then((value,reject) => {
dic['status'] = 200;
dic['data'] = {"message": value};
response.send(dic);
});
and here are the logs in the firebase cloud console:
UPDATE
well after searching for answers in the web, ,i found that I didn't have a suitable 'driver' for linux systems,
so I replace the chrome driver for mac(which work on my machine, on the local host version),
with a chrome driver, for linux. and try again, well that doesn't work either , but at lest I was getting a new log with an Error, not just a 'crash' , here it his:
so now I know that I need to install the chrome browser binary for linux on the project,
any ideas to how can I do this, Im trying to install the chrome binary driver on to my project in firebase, there a few ways im trying now, like installing the chrome binary using the google shell some how, any help or idea to I do does, even so, I don't sure that after the binary will be install , this will be it, and the driver will work on the firebase servers..
Preamble
To start off, I'm not a developer; I'm just an analyst / product owner with time on their hands. While my team's actual developers have been busy finishing off projects before year-end I've been attempting to put together a very basic API server in Node.js for something we will look at next year.
I used Swagger to build an API spec and then used the Swagger code generator to get a basic Node.js server. The full code is near the bottom of this question.
The Problem
I'm coming across an issue when writing out to a log file using the fs module. I know that the ENOENT error is usually down to just specifying a path incorrectly, but the behaviour doesn't occur when I comment out the Swagger portion of the automatically generated code. (I took the logging code directly out of another tool I built in Node.js, so I'm fairly confident in that portion at least...)
When executing npm start, a few debugging items write to the console:
"Node Server Starting......
Current Directory:/mnt/c/Users/USER/Repositories/PROJECT/api
Trying to log data now!
Mock mode: disabled
PostgreSQL Pool created successfully
Your server is listening on port 3100 (http://localhost:3100)
Swagger-ui is available on http://localhost:3100/docs"
but then fs throws an ENOENT error:
events.js:174
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open '../logs/logEvents2021-12-24.log'
Emitted 'error' event at:
at lazyFs.open (internal/fs/streams.js:277:12)
at FSReqWrap.args [as oncomplete] (fs.js:140:20)
Investigating
Now normally, from what I understand, this would just mean I've got the paths wrong. However, the file has actually been created and the first line of the log file has been written just fine
My next thought was that I must've set the fs flags incorrectly, but it was set to 'a' for append:
var logsFile = fs.createWriteStream(__logdir+"/logEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Log File to location: %s \nWith error description: %s',__logdir, err);
});
Removing Swagger Code
Now here's the weird bit: if I remove the Swagger code, the log files write out just fine and I don't get the fs exception!
This is the specific Swagger code:
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
};
var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, '/api/openapi.yaml'), options);
var app = expressAppConfig.getApp();
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
console.info('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.info('Swagger-ui is available on http://localhost:%d/docs', serverPort);
}).on('error',console.error);
When I comment out this code, the log file writes out just fine.
The only thing I can think that might be happening is that somehow Swagger is modifying (?) the app's working directory so that fs no longer finds the same file?
Full Code
'use strict';
var path = require('path');
var fs = require('fs');
var http = require('http');
var oas3Tools = require('oas3-tools');
var serverPort = 3100;
// I am specifically tried using path.join that I found when investigating this issue, and referencing the app path, but to no avail
const __logdir = path.join(__dirname,'./logs');
//These are date and time functions I use to add timestamps to the logs
function dateNow(){
var dateNow = new Date().toISOString().slice(0,10).toString();
return dateNow
}
function rightNow(){
var timeNow = new Date().toTimeString().slice(0,8).toString();
return "["+timeNow+"] "
};
console.info("Node Server Starting......");
console.info("Current Directory: " + __dirname)
// Here I create the WriteStreams
var logsFile = fs.createWriteStream(__logdir+"/logEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Log File to location: %s \nWith error description: %s',__logdir, err);
});
var errorsFile = fs.createWriteStream(__logdir+"/errorEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Error Log File to location: %s \nWith error description: %s',__logdir, err);
});
// And create an additional console to write data out:
const Console = require('console').Console;
var logOut = new Console(logsFile,errorsFile);
console.info("Trying to log data now!") // Debugging logging
logOut.log("========== Server Startup Initiated ==========");
logOut.log(rightNow() + "Server Directory: "+ __dirname);
logOut.log(rightNow() + "Logs directory: "+__logdir);
// Here is the Swagger portion that seems to create the behaviour.
// It is unedited from the Swagger Code-Gen tool
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
};
var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, '/api/openapi.yaml'), options);
var app = expressAppConfig.getApp();
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
console.info('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.info('Swagger-ui is available on http://localhost:%d/docs', serverPort);
}).on('error',console.error);
In case it helps, this is the project's file structure . I am running this project within a WSL instance in VSCode on Windows, same as I have with other projects using fs.
Is anyone able to help me understand why fs can write the first log line but then break once the Swagger code gets going? Have I done something incredibly stupid?
Appreciate the help, thanks!
Edit: Tried to fix broken images.
Found the problem with some help from a friend. The issue boiled down to a lack of understanding of how the Swagger module works in the background, so this will likely be eye-rollingly obvious to most, but keeping this post around in case anyone else comes across this down the line.
So it seems that as part of the Swagger initialisation, any scripts within the utils folder will also be executed. I would not have picked up on this if it wasn't pointed out to me that in the middle of the console output there was a reference to some PostgreSQL code, even though I had taken all reference to it out of the main index.js file.
That's when I realised that the error wasn't actually being generated from the code posted above: it was being thrown from to that folder.
So I guess the answer is don't add stuff to the utils folder, but if you do, always add a bunch of console logging...
I'm trying to create an error message/log using "winston-mongodb" while sending it to my database. In my MongoDB Compass it created a log folder as expected, but there's no data in it.
Here's my code:
index.js
require("winston-mongodb");
winston.add(new winston.transports.MongoDB({ db: "mongodb://localhost/vidly_node_js" }));
genres.js
router.get("/", async (req, res) => {
throw new Error("Could not get the genres.");
const genres = await Genre.find().sort("name");
res.send(genres);
});
I'm supposed to be getting this:
But this is what I keep getting:
What am I missing???
Also "throw new Error("Could not get the genres.")" is making the code down below in my get function "unreachable". Maybe that's the reason? If so, what do I need todo to fix it? Because it’s giving me an error that says:
TypeError: common.clone is not a function
Upagrade winston-mongodb package to version 4+ to work with latest winston
https://github.com/winstonjs/winston-mongodb/issues/108
Winston 3 and mongodb 3 support is now in the winston-mongodb 4.x branch.
winston-mongodb 3.0 is not compatible with latest winston
https://github.com/winstonjs/winston-mongodb/tree/v3.0.1
Current version supports only mongodb driver version 2.x. If you want to use winston-mongodb with mongodb version 1.4.x use winston-mongodb <1.x.
I am trying to learn Appium, using the instructions given in the documentation:
http://appium.io/docs/en/about-appium/getting-started/?lang=en
I have put this code into a file called AppiumTest.js
const wdio = require('webdriverio');
const opts = {
port: 4723,
desiredCapabilities: {
platformName: "Android",
platformVersion: "8.0",
deviceName: "Pixel_API_26",
app: "C:/Users/SStaple/AppData/Local/Android/Sdk/ApiDemos-debug.apk",
automationName: "UiAutomator2"
}
};
const client = wdio.remote(opts);
client
.init()
.click("~App")
.click("~Alert Dialogs")
.back()
.back()
.end();
I am running it from the Node.js command prompt, using the command: node AppiumTest.js, after starting the Appium Server. It was also necessary to have an Android 8 emulator running.
(Appium Server v1.7.1)
I am getting an output in the Appium Server window. There are a number of errors. The first error shown is this:
Error "Command 'C\:\\Users\\SStaple\\AppData\\Local\\Android\\Sdk\\build-tools\\26.0.2\\aapt.exe d badging C\:\\Users\\SStaple\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\node_modules\\appium\\node_modules\\appium-uiautomator2-driver\\uiautomator2\\appium-uiautomator2-server-v0.1.8.apk' exited with code 1" while getting badging info
I have tried running this command on its own in the Command Prompt:
C:\Users\SStaple\AppData\Local\Android\Sdk\build-tools\26.0.2\aapt.exe d badging C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk
The result I get here is this:
W/zipro (13656): Error opening archive C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk: Invalid file
ERROR: dump failed because no AndroidManifest.xml found
Any ideas?
Update 28/12/2017 - I found the solution!
The file in question looked suspect. It was 0Kb in size!
I downloaded the apk file from https://github.com/appium/appium-uiautomator2-server/releases and used that instead.
This one is 1,518 KB in size.
(Apparently there is some problem with npm not putting that apk file into the right place while beta is installed.)
Having fixed that, I can move on to the next problem!
Its a known issue with apk signing.
You can start with trying to update dependencies:
npm install appium-uiautomator2-driver
npm install appium-adb
If it didn't help, there is more you can try (but that was for Linux):
modify
./node-v6.11.4-linux-armv7l/lib/node_modules/appium/node_modules/appium-adb/build/lib/tools/apk-signing.js so it would return a true even if it looks not signed.
case 20:
context$1$0.prev = 20;
context$1$0.t0 = context$1$0’catch’;
_loggerJs2[‘default’].debug(“App not signed with debug cert.”);
return context$1$0.abrupt(‘return’, true);
Our application is developed using electron framework. it is a standalone application. I have seen that spectron is the framework which is used to automate electron application. but i am not sure whether it is applicable for desktop application. Please confirm the same.
I have installed nodejs and spectron.
I have written a code launch application as mention in the following site
https://electron.atom.io/spectron/
File Name : First.js
var Application = require('spectron').Application
var assert = require('assert')
var app = new Application({
path: 'C:\Users\ramass\AppData\Local\Programs\ngsolutions\ngsolutions.exe'
})
app.start().then(function () {
// Check if the window is visible
return app.browserWindow.isVisible()
}).then(function (isVisible) {
// Verify the window is visible
assert.equal(isVisible, true)
}).then(function () {
// Get the window's title
return app.client.getTitle()
}).then(function (title) {
// Verify the window's title
assert.equal(title, 'My App')
}).then(function () {
// Stop the application
return app.stop()
}).catch(function (error) {
// Log any failures
console.error('Test failed', error.message)
})
i have tried to run the script using command
node First.js
But i am getting error saying that
C:\spectronprgs>node First.js
Error: Cannot find module 'spectron'
Please let me know whether I am going towards right path
how to launch .exe file using spectron framework
how to run the script
run the following from the command line.
npm install --save-dev spectron
Then see if you can find the module. You never mentioned in your post how you installed spectron.