Simplest node express web API

For frontend dev, the simplest web API to joke around with.

Create the project and install express package

npm init
npm install express

Node server

Create server.js file in the root.

// ./server.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
    res.send({ message: "I'm here"});
});

app.listen(3000, () => console.log('Listening on port 3000!'));

Run it

node server.js

Test it

curl localhost:3000

Package it in a docker container

# ./Dockerfile
FROM node
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Build and run

docker build -t node-server .
docker run node-server -p 3000:3000

Test it

curl localhost:3000