gpt-3.5-turbo-0125· openai
from WildChat-4.8M
Write 10 random nodejs usefull codes
- User
Write 10 random nodejs usefull codes
- Assistant
- To create a basic HTTP server in Node.js:
javascriptconst http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/html'}); res.write('Hello, world!'); res.end(); }); server.listen(3000, () => { console.log('Server running on port 3000'); });- To read a file in Node.js:
javascriptconst fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });- To make a request to an API using the
axioslibrary:
javascriptconst axios = require('axios'); axios.get('https://jsonplaceholder.typicode.com/posts/1') .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });- To parse JSON data in Node.js:
javascriptconst jsonData = '{"name": "John", "age": 30}'; const obj = JSON.parse(jsonData); console.log(obj.name);- To create a simple timer in Node.js:
javascriptsetTimeout(() => { console.log('Timer expired'); }, 5000);- To generate a random number in a specified range in Node.js:
javascriptconst min = 1; const max = 10; const randomNum = Math.floor(Math.random() * (max - min + 1) + min); console.log(randomNum);- To exit a Node.js process:
javascriptprocess.exit();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.