3. Introduction to Web Backend Using JavaScript
Setting Up a Simple Node.js Server
Initialize a Node.js Project:
npm init -yInstall Express:
npm install expressCreate a Simple Server:
Create
server.js:
const express = require('express'); const app = express(); const port = 5000; app.get('/', (req, res) => { res.send('Hello from the backend!'); }); app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); });Run the server:
node server.js
Connecting Backend with GenAI API
Install Axios:
Create an Endpoint to Call GenAI:
Update
server.js:
Testing the Endpoint:
Use a tool like Postman to send a
POSTrequest tohttp://localhost:5000/chat.
Last updated