How to RUN a NodeJS application in Docker

Dockerfile

FROM node:14-alpine3.15 

WORKDIR /app

RUN chown -R node /app

USER root

COPY package.json .

RUN npm install 

COPY . . 

EXPOSE 8080 

CMD [ "node", "server.js" ]

Server.js

const express = require('express');

const app = new express(); 

const port = process.env.PORT || 8080 ; 

app.get('/', (req, res)=>{
    res.send('AWS With Atiq');
});

app.listen(port, ()=>{
    console.log('app started');
})

Leave a Comment

Your email address will not be published.