Why is body-parser struck thru w/ line in my VSCode and how to get it to function? - crud

Building a MERN CRUD app and read thru StackOverflow. Saw body-parser has been deprecated. Followed additional instructions and still getting line strike. Does this line strike thru body-parser matter? Does this mean body-parser is not functioning for my code? Thanks for taking the time to read my question. Much appreciated.
dependencies
body-parser with line strike thru

Found answer to my question: body parser use to be built into express core library. Then, they separated body parser. The newest update to express has gone back to the older arrangement of including body parser shipping with core express library.
Old way:
app.use(bodyparser.urlencoded({ extended: true}))
Latest version as of 2021 way:
app.use(express.urlencoded({ extended: true}))

Related

Is the ddd() helper not working in Laravel 9?

I upgraded to Laravel 9 the other day, and now the ddd() helper is failing with the error Call to undefined function ddd(). I found this post on the Laracasts forum, but at time of writing there is only a single reply that states that the facade/ignition was replaced with spatie/laravel-ignition. I did not see anything in the documentation for the new package that mentions anything changing with ddd(), is there an additional configuration or something that is needed to re-enable ddd()?
Take a look at this https://github.com/facade/ignition/pull/201#event-2712168617
jasonvarga deleted the ddd branch 2 years ago
And you are right about not seeing any documentation about it in changelogs as well.
I heard this ddd() helper for the first time from you, so thax for that.
Please do check out the documentation of both of the packages.
Here facade / ignition and spatie / laravel-ignition
Both packages saying the same thing that
spatie/laravel-ignition works for Laravel 8 and 9 applications running
on PHP 8.0 and above. Looking for Ignition for Laravel 5.x, 6.x or 7.x
or old PHP versions? facade/ignition is still compatible.
In spatie/laravel-ignition version 1.2.0, ddd() was added back in! If you are not able to use ddd(), first check your composer.json file to make sure that your spatie/laravel-ignition version is 1.2.0 or above.
"require-dev": {
"spatie/laravel-ignition": "^1.2.3"
}

firebase-admin - Auth error:TypeError: URL is not a constructor

I've got a node API that uses firebase-admin to handle firestore data. This wasn't a problem till a few days ago and now it started happening.
The weird thing is, I only seem to get this on my production server and not on local development environment(even using the same database).
I've tried redeploying, restarting the server, checked database configuration and everything and nothing really worked.
This is one of the more detailed errors:
Error: 14 UNAVAILABLE: Getting metadata from plugin failed with error: URL is not a constructor
at Object.exports.createStatusError (/root/apps/api/src/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/root/apps/api/src/node_modules/grpc/src/client_interceptors.js:845:24)
And this is my connection file:
import * as admin from 'firebase-admin'
import serviceAccount from './fbAdminKey'
admin.initializeApp({
projectId: '<myProjectId>',
credential: admin.credential.cert(serviceAccount),
databaseURL: '<myDbURL>'
})
const db = admin.firestore()
const messaging = admin.messaging()
const auth = admin.auth()
export default { db, messaging, auth }
It should be able to just connect to the database and do the operations, I have an app, a web application and they all work normally, just the node API seems to be acting weirdly.
So, after banging my head around for nearly a week, having other problems and stuff, I could figure it out with the help of everybody here.
The problem was the node.js version
I was running node 8.4.0 locally and node 6.x.x on production. (firebase-admin 7.0.0)
So I updated it on production using nvm and than got another problem, related to the grpc version. I had a newer version installed and it was requiring an older one.
Note
If you are using PM2, make sure to update it as well:
http://pm2.keymetrics.io/docs/usage/update-pm2/
After that it started working again and it stuff is back on track.
Not the exact solution because it doesn't solve the problem with Node 6.11.5.
The production server runs by default on Node 6.11.5 and if you wanted to change the runtime version to 8, then refer to this article.
https://firebase.google.com/docs/functions/manage-functions#set_runtime_options
However, keep in mind that this runtime version is currently in beta, so it might break.
I also noticed, that I was able to get rid of this error that you were facing by installing previous version of firebase-admin (6.2.0 to be specific, as for now - the version 7.x.x is the latest one).
I'm afraid that one of the newer firebase-admin versions broke this feature in some environments and that's why this issue is not that common.

String functions not working in electron app

I have a .js file inside an electron app that uses the quasar framework.
inside this file i have axios to make requests to my api to pull data
once i get the response i use the data for further processing. However i need some string functions to escape some strings and when i try .replace it just fails.
var t = JSON.parse(JSON.stringify(someObj))
console.log(t.message.replace(/"/g, '\\"');)
the app just fails to build and tells me there is some error in x line. if i use console.log(t.message) i see that it print the text in the terminal console, so i know the value is not null.
Also when i hover my mouse over the variable it tells me (any) not sure what this means.
image:
P.S: this is my first time working this tech stack.
turned out there was a configuration issue with babel inside electron that was using quasar framework, it didn't not accept commonjs as module and hence no vanilla javascript would work.
Just had this issue myself, I know you've answered your own question but if you can use nodejs you can install replace-string from npm and use it
command: npm install replace-string
link:
https://www.npmjs.com/package/replace-string
This issue has literally caused me a morning of work - but hope someone finds this post and fixes this issue quicker!

Using sass with expressjs

What is the best way to use sass with express.js framework. I am starting from teh point where I have already done
npm install sass
I believe previously with express 2.x one could do something like -
app.use(express.compiler({ src: pub, enable: ['sass'] }))
But with express 3.x it gives me error :
app.init();
return app;
} has no method 'compiler'
What is the alternative statement to include in express 3.x?
Similarly if one could let me know the same on how to plugin coffeescript that would be great help.
I have seen examples of using Cakefile to precompile, but is that the only solution? That would mean adding an extra step of running a Cake task. What advantage would that have as against something defined within express app.js / app.coffee.
I have looked at connect-assets (which does coffeescript but not sass) and somewhere one also mentioned about connect-assetmanager pre hook, but haven't been able to make that work.
https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x says:
template engine compliance from engine.compile(str, options) => Function to engine.__express(filename, options, callback)

Basic Express + Stylus setup question (getting ENOENT)

UPDATE: After updating to stylus 0.7.4 and express 2.3.12 I can no longer reproduce this. Presumably it was a bug somewhere in an earlier version of stylus.
I'm trying to get the most basic express + stylus setup hooked up. I want to have screen.styl rendered into css and returned in the response when a GET for /screen.css is handled.
I've debugged into the stylus middleware and the debugger is jumping around in ways I can't follow. The stylus middleware code looks fine, but a GET /screen.css is resulting in a Error: ENOENT, No such file or directory '/Users/plyons/projects/test_stylus/screen.css' going out in the response.
I have a test directory with just 2 files (the server is in coffeescript, but it's trivial).
screen.styl server.coffee
cat server.coffee
express = require 'express'
app = express.createServer()
app.use require('stylus').middleware(__dirname)
app.use express.static __dirname
app.listen 9800
cat screen.styl
a
background-color red
From staring at the stylus middleware.js file for quite a while, I think this should work. The stylus middleware is definitely executing and attempting to do fs.stat on both the .styl file, which exists, and the .css file, which does not yet exist, thus the ENOENT, but the middleware looks like it should detect that ENOENT and handle it without any problems (compile the .styl and save the result in the .css). But no .css file is being written. If it was written, the system is designed for the middleware to call next() without actually sending anything in the response, but then the static provide would find the .css file and send it as the response, right?
Anyone know what I've got wrong here?
UPDATE: After updating to stylus 0.7.4 and express 2.3.12 I can no longer reproduce this. Presumably it was a bug somewhere in an earlier version of stylus.