How to run a Node.js Express server?


I am trying to write a simple Node.js Express server which I can use to connect to my AWS S3 bucket, currently I cannot even start the server, I have managed to start it for the first time but after closing the terminal I can no longer start it nor do I know which port it is possibly still running on.

I tried running the following commands to start it:
‘node .’
‘node index.js’

The only thing I get is a terminal window popping up which disappears after a second or so.

I have tried restarting my machine to see if that would work no success.

My simple node.js code:

const app = require('express');
const AWS = require('aws-sdk');
const express = require('express');
const PORT = 8080;


const awsKey = 'randomkey';
AWS.config.update({region: 'eu-west-2'});

const s3 = new AWS.S3();

app.get('/image', (req, res) => {
     let params = {Bucket: 'competitionimagebucket', Key: awsKey};
    s3.getObject(params, (err, data) => {
        "text": 'hello'

app.listen(PORT, () => console.log('Server running on Port ' + PORT));

My package.json file

  "name": "express",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "aws-sdk": "^2.1457.0",
    "express": "^4.18.2"


Looks like you are importing app rather than express so change it to this:

const express = require('express')

const app = express() 

You have to call the function and what it returns we want to call it app.

Try this and send if you are getting some errors
check out this documentation

Answered By – Jonathan Sanchez

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published