Commit 2c777bc amrutha
committed
1 parent 76bf6b2 commit 2c777bc Copy full SHA for 2c777bc
File tree 4 files changed +862
-27
lines changed
4 files changed +862
-27
lines changed Original file line number Diff line number Diff line change
1
+ FROM node:18-alpine
2
+ WORKDIR /app
3
+ COPY . .
4
+ RUN npm install
5
+ CMD ["node" , "index.js" ]
Original file line number Diff line number Diff line change 1
- const readline = require ( 'readline' ) ;
2
- const convert = require ( './convert' )
3
- const rl = readline . createInterface ( {
4
- input : process . stdin ,
5
- output : process . stdout
1
+ const express = require ( 'express' ) ;
2
+ const convert = require ( './convert' ) ; // Ensure this file exists and exports a function
3
+ const app = express ( ) ;
4
+
5
+ app . use ( express . json ( ) ) ;
6
+
7
+ app . get ( '/convert' , ( req , res ) => {
8
+ const { inr } = req . query ;
9
+
10
+ if ( ! inr ) {
11
+ return res . status ( 400 ) . json ( { error : 'Missing required query parameters' } ) ;
12
+ }
13
+
14
+ try {
15
+ const usd = convert ( inr ) ;
16
+ res . json ( { inr, usd } ) ;
17
+ } catch ( e ) {
18
+ res . status ( 500 ) . json ( { error : e . message || 'Conversion error' } ) ;
19
+ }
6
20
} ) ;
7
- const promptUser = ( ) => {
8
- rl . question ( 'Enter amount (INR): ' , ( input ) => {
9
- if ( input . toLowerCase ( ) === 'exit' ) {
10
- console . log ( "Goodbye!" ) ;
11
- rl . close ( ) ;
12
- return ;
13
- }
14
- const inr = parseFloat ( input ) ;
15
- try {
16
- const usd = convert ( inr ) ;
17
- console . log ( `INR ${ inr } = USD ${ usd } \n` ) ;
18
- } catch ( e ) {
19
- console . log ( e ) ;
20
- }
21
- promptUser ( ) ;
22
- } ) ;
23
- } ;
24
- promptUser ( ) ;
21
+
22
+ const PORT = process . env . PORT || 3000 ;
23
+ app . listen ( PORT , ( ) => console . log ( `Server running on port ${ PORT } ` ) ) ;
You can’t perform that action at this time.
0 commit comments