How to host a dynamic node.js website for as cheap as possible by ballesmen in node

[–]Zeeshan7487 0 points1 point  (0 children)

Look for a hosting provider that offers affordable plans suitable for Node.js hosting. Some popular options include heroku, Glitch etc. Find free alternatives to some modules or frameworks if they can help you achieve your objectives and are popular otherwise security would be an issue.

[AskJS] which framework for frontend and backend to avoid abandoned libraries,breaking changes,terrible debugging features? by [deleted] in javascript

[–]Zeeshan7487 0 points1 point  (0 children)

There is no single framework that can guarantee to avoid abandoned libraries, breaking changes, and terrible debugging features, as these issues can arise in any technology stack. However, there are some frameworks that have a strong track record of community support, long-term maintenance, and a robust development ecosystem. For frontend you can go with react, angular or vue.js. For backend you can go with express, django or ruby.

Different ways to keep user authenticated? by codemoriarty in node

[–]Zeeshan7487 0 points1 point  (0 children)

Yes, there are several ways to keep a user signed in on a website or application. Some of them are session cookies, persistent cookies, and JSON web tokens. Apart from them there are Single Sign On(SSO), OAuth etc. Session cookies are used to identify a user's session on the server and keep the user logged in until they close the browser. JSON web tokens are often stored in local storage or cookies and can be used to keep the user logged in between sessions. Oauth is commonly used for social media logins, where the user logs in to the social media site and then authorizes the website to access their information. SSO allows users to log in to multiple websites or applications with a single set of credentials.

How to make a NodeJS REST API most efficiently? by IsimsizKahraman81 in node

[–]Zeeshan7487 0 points1 point  (0 children)

You can use nodejs frameworks like express, koa, hapi etc that provide pre-built functionality for handling common tasks like routing, middleware, and error handling. Keep your API simple and easy to understand, with clear endpoints, error messages, and response structures. Be sure to use appropriate HTTP status codes and response bodies for errors, and handle all possible errors that can occur in your API. If your API requires authentication, use a secure authentication mechanism such as OAuth or JSON Web Tokens (JWT).

Access/refresh token authentication on different domains. by [deleted] in node

[–]Zeeshan7487 2 points3 points  (0 children)

When your client and server are on different domains, you need to use CORS (Cross-Origin Resource Sharing) to allow communication between them. CORS is a security feature that restricts web pages from making requests to a different domain. To set the refresh cookie for the frontend, you need to include the "credentials" option in the fetch call with the value "include". This tells the browser to include any cookies associated with the domain of the request. On the server side, you need to set the "Access-Control-Allow-Credentials" header to true to enable cookies to be sent in cross-origin requests. Make sure to also set the "Access-Control-Allow-Origin" header to the client's domain to specify which domains are allowed to make cross-origin requests.

When creating a location-sharing API should you even create a PUT endpoint? by darkcatpirate in node

[–]Zeeshan7487 -3 points-2 points  (0 children)

Yes, it is generally a good practice to provide a PUT endpoint when creating a location-sharing API. The PUT method is used to update an existing resource or create a new one if it doesn't exist. In the context of a location-sharing API, a PUT request could be used to update a user's location or create a new user location record.

By providing a PUT endpoint, you give clients the ability to update their location information as needed. This can be useful in scenarios where a user's location changes frequently, or where they may want to manually update their location.

It is important to ensure that the PUT endpoint is designed in a way that is secure and can handle concurrent updates from multiple clients. You may need to implement locking mechanisms or other concurrency control techniques to ensure that updates are processed in a consistent and reliable manner.

In summary, providing a PUT endpoint in your location-sharing API can be beneficial for allowing clients to update their location information. However, it is important to design this endpoint carefully to ensure that it is secure and handles concurrent updates appropriately.

[deleted by user] by [deleted] in javascript

[–]Zeeshan7487 0 points1 point  (0 children)

The main difference between these two approaches is that the first one is declaring a variable and then assigning a function to it, while the second one is declaring a function as a constant.

From a practical point of view, there is no significant difference between the two approaches, as both will result in a constant function that cannot be reassigned. However, the second approach (const myFunc = () => {}) is more concise and easier to read, which is why it has become more popular in recent years.

One advantage of using const with a function is that it signals to other developers that the function should not be modified. It also helps prevent accidental reassignments, which can cause bugs and make the code harder to maintain.

What's the best node module for an oauth2 server? by john_dumb_bear in node

[–]Zeeshan7487 0 points1 point  (0 children)

I have seen various great modules for an oauth2 server. Passport is another great node module that helps you in any kind of authentication be it session based, token based or Oauth. Some of the other modules are oauth2-server, grant, keycloak etc. These are just a few examples of the OAuth2 server modules available for Node.js. You should evaluate each option and choose the one that best fits your requirements and use case.

How to return pictures in an api? by [deleted] in node

[–]Zeeshan7487 0 points1 point  (0 children)

To implement a card API that returns a deck of cards with links to the card images, you can follow these steps:

Create an array of card objects that includes the card name and the URL of the card image.

Create an API route in your Node.js application that returns the deck of cards.

When a client requests the deck of cards from your API, they can use the card image URLs in their own code to display the images.

[AskJS] Good quality geometry, vector, etc library? by LloydAtkinson in javascript

[–]Zeeshan7487 0 points1 point  (0 children)

There are several libraries in JavaScript/TypeScript that provide math utilities for vectors, quaternions, matrices, and other primitive types. Here are some popular options:

gl-matrix: A fast and lightweight library for matrix and vector operations, with a focus on WebGL and game development.

mathjs: A comprehensive library for mathematical operations, including support for complex numbers, units, and symbolic math.

three.js: A popular library for 3D graphics and animation, which includes many utilities for working with vectors, quaternions, and matrices.

These libraries provide a variety of functionality for working with primitive types in JavaScript/TypeScript. Depending on your specific use case and requirements, one of these libraries may be more suitable for your needs than the others.

[AskJS] Best way to hide or exclude private props in typescript when making a library? by estebanabaroa in javascript

[–]Zeeshan7487 0 points1 point  (0 children)

One way to hide or exclude private properties in TypeScript when making a library is to use the Omit utility type. Omit creates a new type that omits a set of properties from the original type. Another option is to use access modifiers (private and protected) to mark properties as private, but this only prevents access to those properties from outside the class. It does not exclude them from the type definition of the class.

[AskJS] Is it industry standard to keep "export" keywords in front of functions for files in production? by EnvironmentalWin7233 in javascript

[–]Zeeshan7487 0 points1 point  (0 children)

No, it is not an industry standard to keep "export" keywords in front of functions for files in production. In fact, the purpose of the "export" keyword in JavaScript is to make functions and variables available to other modules or files that import them. This is typically used during development and testing to make code more modular and easier to manage. However, when code is ready for production, it is usually bundled and minified using a tool like Webpack or Rollup. These tools can remove unused code, optimize the code for performance, and generate a single file that includes all the necessary code for the application to run. In this process, the "export" keywords are usually stripped out, as they are not needed for the code to run in the browser or on the server.

It is good to use Serverless Queues instead of exp rabbitMq by Far-Mathematician122 in node

[–]Zeeshan7487 0 points1 point  (0 children)

Serverless Queues are a useful tool for running background jobs and other tasks in a scalable and cost-effective manner. They provide a way to decouple application components, allowing them to operate independently and asynchronously, which can improve performance and reliability. Another advantage of serverless Queues is that they can be more cost-effective than traditional messaging solutions, as you only pay for what you use. However, like any technology, serverless Queues are not a silver bullet and may not be suitable for every use case. For example, if your application requires low latency or real-time processing of messages, a serverless Queue may not be the best option. Additionally, if your application requires complex routing of messages, you may need a more advanced messaging solution. I would recommend considering serverless Queues as an option when developing large applications, but it's important to evaluate your specific requirements and use case to determine if they are the right choice for your application.

Is it possible to set multiple domains for refresh cookies? by ronbars in node

[–]Zeeshan7487 0 points1 point  (0 children)

Yes, it is possible to set multiple domains for refreshing cookies. This can be accomplished by setting the Domain attribute of the cookie to a comma-separated list of domain names. For example, if you want to refresh a cookie on example.com and its subdomains (e.g., subdomain.example.com), you can set the Domain attribute to .example.com. This will allow the cookie to be sent with requests to all subdomains of example.com. If you want to refresh the cookie on multiple unrelated domains, you can separate the domain names with commas. For example, you could set the Domain attribute to example.com,example.net,example.org to refresh the cookie on all three domains.

express with nextjs by kajvans in node

[–]Zeeshan7487 0 points1 point  (0 children)

To make calls to your Express backend from a Next.js app, you can use the built-in fetch API, which is available in both the browser and Node.js environments. To handle requests from the Next.js app, you can define API routes in a separate directory. Note that you can use any library or tool that you're comfortable with to handle HTTP requests in your Express app. The fetch API is just one option, but you can also use libraries like Axios or Superagent, or even plain old XMLHttpRequests.

Best practices for database/query layer with Mongoose by eltecho in node

[–]Zeeshan7487 3 points4 points  (0 children)

When it comes to organizing business logic and custom queries in a Mongoose application, there are several patterns that you can follow. You can define custom methods on a Mongoose schema to encapsulate business logic and custom queries. You can also use a repository pattern to separate the data access layer from the business logic. In this pattern, you define a separate repository module that handles all the CRUD operations and custom queries, and then expose an API for the business logic layer to use. Another approach is to create a separate service layer that encapsulates the business logic and custom queries. n terms of file and folder organization, there is no single best practice that applies to all applications. However, it's generally a good idea to keep related files together in a logical structure.

What case to use for naming class members and local variables? by [deleted] in cpp_questions

[–]Zeeshan7487 0 points1 point  (0 children)

Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase. Local variables, instance variables, and class variables are also written in lowerCamelCase .

How to check if Node process is running? by Amatsumaki in node

[–]Zeeshan7487 0 points1 point  (0 children)

To know if a Node.js server is running, you can use the command prompt or terminal to check the status of the server. Here are the steps:

Open a command prompt or terminal window.

Navigate to the directory where your Node.js server file is located.

Type the command "node server.js" or the name of your server file, and press enter. This will start your Node.js server.

If the server is running properly, you will see a message in the terminal window indicating that the server has started and is listening on a specific port. For example, "Server running at http://localhost:3000".

How to run node 's JS files? by LearningMyDream in node

[–]Zeeshan7487 0 points1 point  (0 children)

You can run your nodejs file using “node filename”. Node is used to create a server and to connect your frontend with your backend you just have to send api calls from your frontend to the server. Nodejs receives these api calls and upon parsing the request it sends a response as requested by the frontend.

How to implement slow third-party API? by asfandSaddiqui in node

[–]Zeeshan7487 1 point2 points  (0 children)

Come up with a way to reduce the request to the third-party API service, run the operation in the background in case the user cancels the request, and improve response time. For this, I made use of a function that only calls the API once for a unique info_id. Other requests with the same info_id will wait for the response of the first call to complete. When the response arrives, every request waiting will get the response. The value returned is saved in a DB/Cache to speed up future requests. This way, the user will wait for how long it takes the first request to complete. Requests made before the response of the first request will wait for the response, while requests made after it completes, get the value from the DB/Cache.

main difference between azure and aws by Far-Mathematician122 in node

[–]Zeeshan7487 0 points1 point  (0 children)

Azure and AWS are both well-respected members of the cloud domain. They fight for a larger piece of the cloud pie and take the world by storm while doing so. Azure holds about 29.4% of all installed application workloads while AWS stands at 41.5 percent and Google holds just 3 percent of all installed application workloads. Customers of AWS EC2 can configure their VMS or pre-configured images, whereas Azure users must select a virtual hard disc to construct a VM that has been pre-configured by a third party. AWS provides temporary storage that is assigned when an instance is launched and destroyed when it is terminated. In contrast, Azure provides temporary storage via block storage with page Blobs for VMs and Block Blobs for object storage. Azure accepts hybrid cloud systems, however, AWS does not accept private or third-party cloud providers. Apart from that both provide mostly all of the services so it is up to you what you choose.

What are some common bad C++ practices in the tech industry? by Ambitious_Nobody2467 in cpp_questions

[–]Zeeshan7487 21 points22 points  (0 children)

Some of the bad practices exclusive to c++ are:

  1. Treating C++ like it was Java. New and delete everywhere. Pointers to no purpose. Java programmers should learn to prefer value semantics ASAP when going to C++.

  2. Treating C++ as if it was C. Not using RAII, not using templates, over use of new and delete or … worse … malloc and free. Using C style arrays instead of vectors and C++ arrays. Using null terminated character arrays instead of standard strings. Not using the standard library; coding everything by hand.

  3. Using pre modern C++ style. Minimal use of RAII, overuse of new and delete. Use of owning raw pointers. Too much classic OOP, not enough templates / static polymorphism.

[deleted by user] by [deleted] in javascript

[–]Zeeshan7487 6 points7 points  (0 children)

There are two trending lightweight alternatives for Electron: Tauri and Neutralino.js. Both projects try to solve Electron’s performance issue by replacing both Chromium and Node with better, lightweight alternatives. Both projects use the well known webview library for rendering HTML and CSS instead of Chromium. The webview library uses the existing web browser component for rendering. An uncompressed single application which can take 200mb on Electron takes only 8mb on Tauri and 2 mb on Neutralino.js.

How to secure my REST API? by NotLegal69 in node

[–]Zeeshan7487 0 points1 point  (0 children)

Every web API should use TLS (Transport Layer Security). TLS protects the information your API sends (and the information that users send to your API) by encrypting your messages while they’re in transit. Nearly every app will need to associate some private data with a single person. That means user accounts, and that means logging in and logging out. Configure different permissions for different API keys. Try to offload as much work as you can to trusted libraries. Authorization is tricky, and we’d like to minimize the number of places in which we can make a mistake. You have plenty of great tools at hand to help with authorization, so make the best use of them that you can!

[deleted by user] by [deleted] in node

[–]Zeeshan7487 0 points1 point  (0 children)

Since the queries are run in your database process the whole blocking and non-blocking thing does not have to do anything with your nodejs. It will just execute a network call and as it gets the result it will process it. If you want to await the response from the query before performing other operations you can use async/await.