Getting Started
suggest changeCreate a directory, open it in a shell, and install Express with npm. npm install express is enough (--save has been the default since npm 5).
Create a file and name it app.js and add the following code which creates a new Express server and adds one endpoint to it (/ping) with the app.get method:
const express = require('express');
const app = express();
app.get('/ping', (request, response) => {
response.send('pong');
});
app.listen(8080, 'localhost');
To run your script use the following command in your shell:
> node app.js
The application accepts connections on localhost port 8080. If the hostname argument to app.listen is omitted, the server also accepts connections on the machine's other addresses. If the port is 0, the operating system assigns an available port.
Once your script is running, you can test it in a shell to confirm that you get the expected response, “pong”, from the server:
> curl http://localhost:8080/ping
pong
You can also open http://localhost:8080/ping in a browser.