create api with endpoint /test in javascript

To create an API with an endpoint /test in JavaScript, you can use Node.js with Express.js framework. Here's an example code:

index.tsx
const express = require('express');
const app = express();

app.get('/test', (req, res) => {
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
201 chars
11 lines

In this example, we create a new Express app and listen on port 3000. We define a route for the /test endpoint using the app.get() method, and send a response with a "Hello World!" message using the res.send() method.

You can run this code with the command node app.js in your terminal or command prompt. Then, you can access the API by going to http://localhost:3000/test in your web browser or using a tool like Postman. This should return the "Hello World!" message in the response.

gistlibby LogSnag