javascript – Unexpected end of the JSON entry when trying to display the main page on nodejs

I'm trying to make the main page in the index page of my node.js server where I'm storing the .json files in my data folder. However, when I try to run my server, it displays "SyntaxError: Unexpected end of the JSON entry" in product.js. , and following the error, here is where he accuses the error

cb (JSON.parse (contentFile));

here is my whole class on how I model my product

const fs = require (& # 39; fs & # 39;);
const path = require (& # 39; path & # 39;);

const p = path.join (
path.dirname (process.mainModule.filename),
& # 39; Data & # 39 ;,
& # 39; produits.json & # 39;
)

const getProductsFromFile = cb => {
fs.readFile (p, (err, fileContent) => {
if (err) {
cb ([])
} other {
cb (JSON.parse (contentFile));
}
});
};

module.exports = class Product {
constructor (title, imageUrl, description, price) {
this.title = title;
this.imageUrl = imageUrl;
this.description = description;
this.price = price;
}

save() {
getProductsFromFile (products => {
products.push (this);
fs.writeFile (p, JSON.stringify (products), err => {
console.log (err);
});
});
}

static fetchAll (cb) {
getProductsFromFile (cb);
}
};

Now, that's the problem, it accuses an analysis error but does not currently store anything in a file. Therefore, I do not know why he gives me this error.

node.js – Management error expected in the firebase command

I've installed Node.Js to use the Firebase tools in my console. For a project, I typed the command npm install -g firebase tools and I've been successful so far, however, typing the firebase login command returns a syntax error, I do not understand why this error appears because the syntax of the file is sent directly from the server. The picture is as follows: insert the description of the image here

Node.js app to keep track of the dynamic IP address of dell edge box?

The border box will have to tell you its new address at each change of address. That is to say. do not think of it as a server you are connecting to, but let it connect elsewhere. For example, the Edge Server can connect to a VPN so that you can assign it a stable logical IP address within your VPN, even if the VPN connection is tunnelled when the connection is changed.

This is a network problem and not a microservice or NodeJs problem. Even if VPNs improve, such a solution is still very fragile. Determine carefully whether connecting to a machine without a stable IP address is really the best solution for your needs. Also determine whether your network operator could assign a stable IP address to the device as part of its commercial offers.

javascript – Nodejs Passport no puedo printed by consola

// router

router.post (& # 39; / signin #, (req, res, next) => {
passport.authenticate (& # 39; local.signin & # 39 ;, {
successRedirect: & # 39; / profile & # 39;
failureRedirect: & # 39; / signin & # 39;
failureFlash: true
}) (req, res, next);
});

//passport

passport.use (& # 39; local.signin & # 39 ;, new LocalStrategy ({
usernameField: 'user',
passwordField: 'pass',
passReqToCallback: true
}, async (req, user, pass, done) => {

console.log (req);
const result = wait pool.query (& # 39; select * among users where name =? & # 39 ;, [user])
// no if the request is made in the case of tampoco sent me to interrogate a consola.
console.log (result);
}));


javascript – How to use ajax queries in node.js

Hello, I am developing an API using node.js, but I would like to make requests to submit certain forms, but without updating the page. I know ajax does this and I used it, but I want to know if I can do it using only the node.js file or if I can use ajax with node and so on. If there is something similar or a tutorial (video or article), thank you for thanking me.

javascript – How to read column data from csv file in nodejs file?

Some of your past responses have not been well received and you may be stuck.

Please pay close attention to the following tips:

  • Please make sure to respond to the question. Provide details and share your research!

But to avoid

  • Ask for help, clarification, or answer other answers.
  • Make statements based on opinions; save them with references or personal experience.

To learn more, read our tips for writing good answers.

node.js – Port numbers do not hide in reverse proxy nginx (next js server)

I'm trying to deploy a next-js app with create-next-app, I've got a custom express server like this –

const express = require (& # 39; express)
const next = require (& # 39; next & # 39;)
const dev = process.env.NODE_ENV! == & # 39; production & # 39;
const nextApp = next ({dev})
const handle = nextApp.getRequestHandler ()

const fs = require (& # 39; fs & # 39;)

nextApp.prepare ()
.then (() => {
const server = express ()


leave port = 3000;

let options = {
key: fs.readFileSync (a key .., & utf-8,),
cert: fs.readFileSync (& some cert .., & # 39; utf-8 & # 39;),
};


server.get (
...
)


let app = https.createServer (options, server)
.listen ((port), function () {
console.log ("listen to the server on the port" + port);
});

})
.catch ((ex) => {
console.error (ex.stack)
process.exit (1)
})

I want to deploy it as a website when a user enters the subdomain.maindomain.com URL. I have therefore saved two nginx configuration files like this one –

/ etc / nginx / sites-available / default AND /etc/nginx/sites-available/subdomain.maindomain.com

the default file contains this

server {

root / var / www / html;
index.html index.htm index.nginx-debian.html;

servername maindomain.com www.maindomain.com;

location / {
# try_files $ uri $ uri / = 404;
proxy_pass http: // localhost: 3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $ http_upgrade;
proxy_set_header Login & # 39; upgrade & # 39 ;;
proxy_set_header Host $ host;
proxy_cache_bypass $ http_upgrade;
}

listening [::]: 443 ssl ipv6only = on; # managed by Certbot
listen to 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;$
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pe$
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

and the subdomain.maindomain.com file looks like this

server {
if ($ host = www.subdomain.maindomain.com) {
return 301 https: // $ host $ request_uri;
} # managed by Certbot


if ($ host = subdomain.maindomain.com) {
return 301 https: // $ host $ request_uri;
} # managed by Certbot


listen to 80;
listening [::]: 80;

root /var/www/subdomain.maindomain.com/somecodefolder/;
index.html index.htm index.nginx-debian.html;

server_name subdomain.maindomain.com www.subdomain.maindomain.com;


location / {

proxy_pass http: // localhost: 3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $ http_upgrade;
proxy_set_header Login & # 39; upgrade & # 39 ;;
proxy_set_header Host $ host;
proxy_cache_bypass $ http_upgrade;
# try_files $ uri $ uri / = 404;
}

}

if I type https://vendor.rollinglogs.com:3000, everything works fine, I see my website working. But when I type https://vendor.rollinglogs.com (without the port number), nothing is displayed. How can I get the content I want when I just type the URL without the port number. I've tried a lot of combinations, but I could not do it. please, help someone I 've been trying for 2 days.

Debug the node.js file of the remote server (Raspberry Pi)

So I work with files from my remote nodeJS server (Raspberry Pi) on my local PC using SFTP in VS code. This configuration works well with the VS code extension. Now, I want my remote nodeJS application to run on my Pi and set debug breakpoints in my local VS code. Is it possible? I can not find any information online about how to proceed.

Is it viable to use NodeJs and MySQL for very large scale applications (instead of PHP)?

I know that this type of question has probably already been asked, but I could not find a precise answer (at least to my problem) on the Web. Sorry in advance.

I am currently unable to continue my project because I am thinking about the technologies to use between PHP and MySQL and NodeJs & MySqL.

The main reason I would like to use the latter is because …

  1. Uses a single thread
  2. Scalable horizontally (which is cheaper for us)

But at the same time, the reason (and the only reason) why I do not use it is that RDBMS operations tend to have a lock.

My question is this: will the lock of the RDBMS block the single thread of NodeJs and thus slow down my application NodeJs if there are many requests?

nodejs – I have an error with the zeit.co platform when downloading my project

When I try to download the project, I receive this alert.

PS C:  Users  Cristian  Desktop  website-node> now
> WARN! Your project is missing a now.json file with a `version` property.
More: https://zeit.co/docs/version-config
> Deployment of ~  Desktop  website-node under

Someone tried to download a project on this page, the format is in Node.js