0

I am not able to run the file server. JS. I’ve tried to add “type”: module In the package.Json and it didn’t work. The first code is server.js and the secondary is package.json. I also think I'm not able to use import and require? I'm not sure.

const express = require('express');
const app = express();
import { getUserList } from './user';

const userList =  getUserList();

app.get('/users', (req, res, next) => {
    return res.status(200).send({
        success: 'true',
        message: 'users',
        users: userList
    });
   
});

app.listen(8000, () => {
    console.log('Example app listening on port 8000!');
});

{
  "name": "learningnodejs",
  "version": "1.0.0",
  "description": "\"\",",
  "main": "server.js",
  
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js --exec babel-node --trace-warnings ...",
    "lint": "eslint src/js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/node": "^15.3.0",
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "nodemon": "^2.0.7"
  },
  "devDependencies": {
    "@babel/cli": "^7.14.3",
    "@babel/core": "^7.14.3",
    "@babel/preset-env": "^7.14.2",
    "babel-cli": "^6.26.0",
    "babel-loader": "^8.2.2",
    "babel-preset-env": "^1.7.0",
    "webpack": "^5.37.0"
  }
}
Daniek
  • 1
  • 1

0 Answers0