gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
write me an exprss nodejs script that when it receives a get on localhost 8000/roblox it…
- User
write me an exprss nodejs script that when it receives a get on localhost 8000/roblox it returns "Hello!"
- Assistant
Certainly! Below is a simple Express.js script that listens for GET requests on
localhost:8000/robloxand responds with "Hello!".First, make sure you have Node.js and npm installed on your machine. If you haven't installed Express yet, you can do so by running:
bashnpm install expressNow, create a file named
app.jsand add the following code:javascriptconst express = require('express'); const app = express(); const port = 8000; // Define a route for GET requests to /roblox app.get('/roblox', (req, res) => { res.send('Hello!'); }); // Start the server app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); });How to Run the Script
- Save the above code in a file named
app.js. - Open a terminal and navigate to the directory where is located.
- Save the above code in a file named