How to use dotenv with Vue.js

If your project was create by using Vue CLI 3, no need to use dotenv to get environment variables. To get environment variables within .env file in your project: Placing the .env file in your project root. In the .env file, specifying environment variables with “VUE_APP_” prefix. VUE_APP_SOMEKEY=SOME_KEY_VALUE. Finally, you can access them with process.env.* … Read more

Node child_process.spawn multiple commands

From Node.js v6 you can specify a shell option in spawn method which will run command using shell and thus it is possible to chain commands using spawn method. For example this: var spawn = require(‘child_process’).spawn; var child = spawn(‘ls && ls && ls’, { shell: true }); child.stderr.on(‘data’, function (data) { console.error(“STDERR:”, data.toString()); }); … Read more

Trigger client-side reload in next.js

Assume, a user is on the http://www.example.com/profile the user has edited the profile and for some reason, you need to reload the same page. If your case is similar to this, you could use Router.reload(); Remember, you must import Router object like this import Router from “next/router”; For more information: https://nextjs.org/docs/api-reference/next/router#routerreload

NodeJS + Express: How to secure a URL

Yep, middleware is exactly what you want. A middleware function is just a function that works just like any other Express route handler, expept it gets run before your actual route handler. You could, for example, do something like this: function requireLogin(req, res, next) { if (req.session.loggedIn) { next(); // allow the next route to … Read more

Express 4.14 – How to send 200 status with a custom message?

You can use: res.status(200).send(‘some text’); if you want to pass number to the send method, convert it to string first to avoid deprecation error message. the deprecation is for sending status directly inside send. res.send(200) // <- is deprecated BTW – the default status is 200, so you can simply use res.send(‘Success 1’). Use .status() … Read more

QueryFailedError: the column “price” contain null values – TypeORM – PostgreSQL

I had a similar issue, and I reported it at the bottom of this thread. You probably have synchronize: true on your ORM configuration. Because of this, every time you run your app Typeorm tries to create the tables. If you have data in your DB, it throws that misleading error. From here: synchronize – … Read more