gpt-3.5-turbo-0125· openai
from WildChat-4.8M
Write a 10 nodejs usefull code with your imagination
- User
Write a 10 nodejs usefull code with your imagination
- Assistant
- Create a simple server using Node.js:
javascriptconst http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello, World!'); }); server.listen(3000, () => { console.log('Server is running on port 3000'); });- Read a file using Node.js:
javascriptconst fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });- Write to a file using Node.js:
javascriptconst fs = require('fs'); fs.writeFile('file.txt', 'Hello, World!', (err) => { if (err) throw err; console.log('File has been saved'); });- Make an HTTP request using Node.js:
javascriptconst https = require('https'); https.get('https://jsonplaceholder.typicode.com/posts', (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); });- Create a basic CRUD API using Express and Node.js:
javascriptconst express = require('express'); const app = express(); app.use(express.json()); let data = []; app.get('/data', (req, res) => { res.json(data); }); app.post('/data', (req, res) => { data.push(req.body); res.send('Data added successfully'); }); app.put('/data/:id', (req, res) => { data[req.params.id] = req.body; res.send('Data updated successfully'); }); app.delete('/data/:id', (req, res) => { data.splice(req.params.id, 1); res.send('Data deleted successfully'); }); app.listen(3000, () => { console.log('Server is running on port 3000'); });
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.