Posts

Showing posts with the label express

Wait for the Google Vision OCR promise in node.js/express and return it

Image
Clash Royale CLAN TAG #URR8PPP Wait for the Google Vision OCR promise in node.js/express and return it I am having problems to return a promise from the Google Vision OCR. Here is the sample code from Google: const vision = require('@google-cloud/vision'); // Creates a client const client = new vision.ImageAnnotatorClient(); /** * TODO(developer): Uncomment the following line before running the sample. */ // const fileName = 'Local image file, e.g. /path/to/image.png'; // Performs text detection on the local file client .textDetection(fileName) .then(results => { const detections = results[0].fullTextAnnotation.text; console.log('Text:'); console.log(detections); }) .catch(err => { console.error('ERROR:', err); }); This will output the full text to the console. If I put the above code into a function and return the variable detections I get only undef...

moment deprecation warning: dates accessor is deprecated. Use date instead

Image
Clash Royale CLAN TAG #URR8PPP moment deprecation warning: dates accessor is deprecated. Use date instead Error info: Deprecation warning: dates accessor is deprecated. Use date instead. Arguments: Error at Moment.dates (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/moment/moment.js:320:98) at eval (eval at compile (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:549:12), <anonymous>:61:39) at returnedFn (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:580:17) at tryHandleCache (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:223:34) at View.exports.renderFile [as engine] (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:437:10) at View.render (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/view.js:135:8) at tryRender (/Users/ephraimguo/Documents/OST_work/bookin...

How to connect reactjs with express api?

Image
Clash Royale CLAN TAG #URR8PPP How to connect reactjs with express api? I had created a new react application and then installed express and body-parser and express-router, Now i want to connect a express Api to the application for event-driven application. How do i connect it ? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Populate from One Model to Another Using Mongoose/MongoDB in Node/Express Application

Image
Clash Royale CLAN TAG #URR8PPP Populate from One Model to Another Using Mongoose/MongoDB in Node/Express Application I am struggling to understand the populate method in Mongoose , while having trouble populating fields from one Mongoose model to another. The first model Schema is: var MprnSchema = new mongoose.Schema({ mprNo: {type: Number, unique: true, required: true}, siteName: String, buildingNo: Number, streetAddress: String, secondAddress: String, townCity: String, postCode: String, supplier: String, siteContactName: String, siteContactNo: String, }); module.exports = mongoose.model("Mprn", MprnSchema); And another Schema is: var FaultSchema = new mongoose.Schema({ jobRef: Number, mprNo: Number, requestedDate: {type: Date, default: Date.now}, attendedDate: {type: Date, default: null}, siteDetails: {type: mongoose.Schema.Types.ObjectId, ref: 'Mprn'}, faultIssue: String, }); However, when I try to p...

Error setting up ES6 production build angular 6 project with node, express

Image
Clash Royale CLAN TAG #URR8PPP Error setting up ES6 production build angular 6 project with node, express I have been trying to setup angular project with node, express and es6 code. It works without ES6 syntax but I am having a problem setting up babel. The project was created using angular-cli. I have installed babel-cli babel-preset-env package . Created .babelrc file for the same. I need to figure out exactly what goes in scripts for production build. package.json { "name": "alask", "version": "0.0.0", "scripts": { "ng": "ng", "start": "node server.js", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "postinstall": "ng build --aot --prod" }, "private": true, "dependencies": { "@angular/animations": "^6.1.0", ...

On click of button, inrementation number by 1

Image
Clash Royale CLAN TAG #URR8PPP On click of button, inrementation number by 1 Trying to make the number increment by 1 on click event, wondering what's the right approach to this? In my render(): {this.state.posts.map(post => <div key={post._id}> <span>Votes: {post.votes}</span> <a href="" onClick={() => this.votePost(post._id)}> Click Me </a> </div> )} initial state: state = { posts: , }; on click function: votePost = async id => { await axios.put(`/posts/${id}`); .... }); this.setState({ posts: newPostData }); }; where are you getting newPostData form? If you are getting it from server then its fine but you need to update that particular post only, No need to reset entire posts. – Pawan Singh 20 mins ago ...

NodeJS/Knex Creating Json Response

Image
Clash Royale CLAN TAG #URR8PPP NodeJS/Knex Creating Json Response I'm currently using NodeJS with knex (Postgresql) for database stuff. Problem: Imagine the following two tables in database: Table 1 PROJECT id (pk) name Table 2 EMPLOYEE id (pk) name project_id (fk) I want to create a json-response to the user that looks like the following: { projects: [ { id: 1, name: 'emxample 1', employees: [ { id: 1, name: 'example 1' }, { id: 2, name: 'example 2' } ] } ] } and so on. Making a query like: knex('projects').select('projects.*', 'employee.*').join('employee', 'employee.project_id', '=', 'project.id') And using res.json() does not returns an array of employees . res.json() employees What is the way to go to achieve that? By clicking "...

Dynamically pick values from req.body based on database attributes

Image
Clash Royale CLAN TAG #URR8PPP Dynamically pick values from req.body based on database attributes I am building an app usine Node/EJS/Mongo where the user is building a capability survey, and needs to set the desired level for each question. The form that they use to pick the levels has a series of selects that look like: <select class="form-control col-sm-4" id="<%=capability.capabilityId%>" name="<%=capability.capabilityId%>"> <option value=1>Developing</option> <option value=2>Intermediate</option> <option value=3>Advanced</option> <option value=4>Role Model</option> </select> When the user then submits this form, I want to update the assessment to load in these expected levels. The schema for assessments in my mongodb looks like: var assessmentSchema = new mongoose.Schema ({ title: String, startDate: Date, endDate: Date, behaviours: [{ behaviourName: String,...

Cross domain from browser to express server doesn't work

Image
Clash Royale CLAN TAG #URR8PPP Cross domain from browser to express server doesn't work I know this has been asked more than a hundred times... I did look into most of the information I found, and think I did understand the process, cause I was able to configure my s3 to allow cross domain access.. my express configuration: this.express = new Express(); this.express.all("*", (req, res, next) => { res.setHeader('Access-Control-Allow-Origin', "*"); res.setHeader('Access-Control-Allow-Methods', "POST"); res.setHeader('Access-Control-Allow-Headers', "content-type"); next(); }).options((req, res, next) => { res.end(); }); *I add a router down the modules folder hierarchy.. When I check the network tab this is what I see: I think that I have answered the CORS challenge, in the pre-flight OPTIONS request, but the second request is not called... WHY? ...