Posts

Showing posts with the label reactjs

How to create an API in Next.js

Image
Next.js , an advanced React framework, streamlines web application development with features like server-side rendering and automatic code splitting. Creating APIs in Next.js is advantageous due to its built-in API routes feature, offering a seamless and integrated approach for handling server-side logic or connecting to databases. This simplifies the development process, ensuring efficient communication between the frontend and backend within the same framework. Route Handlers allow you to create custom APIs. Note: Route Handlers are only available inside the app directory.  Route Handlers are defined in a route.js|ts file inside the app directory. app/api/route.ts export const dynamic = 'force-dynamic' // defaults to auto export async function GET(request: Request) {} Supported HTTP Methods are: GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS . Example: export async function GET() {   const res = await fetch('https://data.mongodb-api.com/...', {     ...

Steps to Configure Postgres in Vercel with your Next.js project

Image
Vercel is a cutting-edge cloud platform renowned for its seamless deployment and hosting solutions, designed to simplify the process of deploying web applications. With its emphasis on serverless computing, global content delivery, and continuous deployment, Vercel empowers developers to focus on building exceptional user experiences. Hosting Postgres on Vercel enhances your application's performance and scalability.  Leveraging Vercel's serverless architecture and global CDN ensures rapid access to your database, while its straightforward integration and automatic scaling capabilities make managing Postgres hassle-free, allowing you to concentrate on crafting robust and efficient applications. Steps 1. Create a project 2. Go to Storage 3. Create Postgres database Connect Store → Create New → Postgres → Continue 4. Copy the secret to .env file 5. Install Postgres sdk npm i @vercel/postgres

NPM is good friend of every web-developer in JavaScript community

Image
                                          Yes! It is true and I feel it too as a beginner, do you feel the same?  Section 1:   What is NPM? NPM stands for Node Package Manager is open source command line tool use as package manager for Node.js, front-end web apps (react app), mobile apps, robots, … and many more. Here we will talk about npm in terms of Node.js only. (I m using windows  10) Section 2:    Installation Lets start it by installing Node.js first because npm comes with  Node.js.  So, head over to official website of nodejs : https://nodejs.org/en/ After Node.js downloaded, To confirm that you have npm installed you can run  below command in your terminal. npm -v Note: that my version is 6.14.8 your version can be different. So there is Package.json file in Node.js project. It is metadata of the project, basi...