I am trying to send a string through serialport in node.js with the following code:
function createSerialPort() {
myPort = new SerialPort('COM3', {
baudRate: 115200, dataBits: 8, parity: 'none', stopBits: 1, flowControl: 0
})
myPort.write("135");
}
Everytime I run it it gives me this error:
(node:8468) UnhandledPromiseRejectionWarning: Error: Opening COM3: Access denied
(node:8468) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8468) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
I have looked everywhere for a fix to this (I am new to using serialport) and the only solution I have found is to do this:
function createSerialPort() {
myPort = new SerialPort('COM3', {
baudRate: 115200, dataBits: 8, parity: 'none', stopBits: 1, flowControl: 0
}, true)
myPort.write("135");
}
That solution then gives me this:
(node:18192) UnhandledPromiseRejectionWarning: TypeError: callback.call is not a function
at SerialPort._error (C:\examplepath\node_modules\#serialport\stream\lib\index.js:198:14)
at C:\examplepath\node_modules\#serialport\stream\lib\index.js:242:12
(node:18192) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:18192) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Related
i want to connect my rfid Reader with nodejs which is using "COM4" port i used serial port to connect with it but i had this error
node recive.js
(node:10567) UnhandledPromiseRejectionWarning: Error: Error: No such file or directory, cannot open COM4
(node:10567) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10567) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
the code :
var SerialPort = require("serialport").SerialPort;
var port = "COM4";
var serialPort = new SerialPort({
path: port,
baudRate: 9600
});
serialPort.on("open", function () {
console.log("-- Connection opened --");
serialPort.on("data", function (data) {
console.log("Data received: " + data);
});
});
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5876) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
How to solve this type of error any suggestions
Your code throws an error at some point in some promise. You can solve it by properly handling the exception.
Ex:
var p = new Promise((resolve, reject) => {
// Some code
});
p.then(res => {
// No errors thrown
}).catch(err => {
// Exception happened. Print the error
console.log(err);
});
when am trying to move the image after inserting into mongo db using the function
var db = require('../config/dbconnect')
module.exports = {
//addProduct:(product,callback)=>
addProduct: (product, callback) => {
//console.log(product)
db.get().collection('product').insertOne(product).then((data) => {
console.log(data)
callback(data.ops[0]._id)
})
}
}
I am getting an error like:
{
acknowledged: true,
insertedId: new ObjectId("61054e43cffb994774d37ab0")
}
(node:6964) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
at E:\Nodejs\ecommerce\helpdesk\product_help.js:11:27
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6964) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6964) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This is error first callback. Try the second argument which is the result.
db.get().collection('product').insertOne(product).then((error,data)=>
{
console.log(data)
callback(data.ops[0]._id)
})
instead of callback(data.ops[0]._id).
Try:
db.get().collection('product').insertOne(product).then((data) => {
callback(data.insertedId)
})
.catch((err)=>console.log('venk error',err))
}
When this is run it gives an error message.
The bot has full admin over the server I am testing it in.
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial); await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if ((reaction.message.channel.id === "744212634446224976") && (reaction.emoji.name === '🚩')) {
reaction.message.guild.members.cache.get(user.id).roles.add('746263081695067178').catch()
}
});
Error message:
(node:17644) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (D:\Projects\Bot-role\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:17644) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17644) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The role being changed has to be under the clients (bots) own.
Change the order under [server] > Server Settings > Roles
when running my Get method in both Swagger and Postman, I get the following error message:
(node:35014) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'error' of null
at HttpErrorFilter.catch (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/src/shared/http-error.filter.ts:28:31)
at ExceptionsHandler.invokeCustomFilters (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/exceptions/exceptions-handler.js:31:26)
at ExceptionsHandler.next (/Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/exceptions/exceptions-handler.js:12:18)
at /Users/mapoferl/Documents/develop/BuergermeisterApp/backendnest/node_modules/#nestjs/core/router/router-proxy.js:12:35
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:35014) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:35014) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
d.service.ts
public async getCorporateDesignByDistrictName(name: string): Promise<CorporateDesign> {
const district: District = await this.districtRepository.createQueryBuilder('district')
.leftJoinAndSelect('district.mandant', 'mandant')
.leftJoinAndSelect('district.corporateDesign', 'corporateDesign')
.where('district.name = :name')
.andWhere('district.isDeleted = :isDeleted')
.setParameters({
name: name,
isDeleted: false
})
.getOne();
return district.corporateDesign;
}
d.controller.ts
#UseGuards(AuthGuard)
#Get(':name')
public async getCorporateDesignByDistrictName(#Param('name') name: string): Promise<CorporateDesign> {
return this.districtService.getCorporateDesignByDistrictName(name);
}
I'm using angular 8 and nest.js