0

I am working on a boiler plate for a typescript based express server. One of my key requirements is to have eslint running with nodemon. In my package.json i have...

"scripts": {
    "start": "node dist/index.js",
    "dev": "nodemon src/index.ts --exec 'eslint . --ext .ts'",
    "build": "tsc -p ."
},

my express app is pretty simple at this point...

import express from 'express';
import { PORT } from './config/constants';

const app = express();
app.use(express.json());

app.get('/api-v1', (req, res) => {
    const test = 3;
    console.log(test);
    res.send('Hello World');
});

app.listen(PORT, () => {
    console.log(`Server is listening on port ${PORT}`);
});

so when I run the dev script "nodemon src/index.ts --exec 'eslint . --ext .ts'" the linting runs, however the express server is never started...I see this in the console:

[nodemon] clean exit - waiting for changes before restart

any thoughts on how to fix this?

Sandra Willford
  • 3,459
  • 11
  • 49
  • 96

1 Answers1

0

The source code is here

I suppose nodemon expects to run a server (which never exits) but the command exited with code 0 (which is successful exit code).

Seems like nodemon call is incorrect.

It currently runs eslint . --ext .ts src/index.ts (which runs successfully and exits with code 0).

I think it should be something like this (see this answer for other options):

"scripts": {
    "start": "node dist/index.js",
    "dev": "tsc-watch --project . --outDir ./dist --onSuccess \"nodemon dist/index.js\"",
    "build": "tsc -p ."
},
Vitalii
  • 2,071
  • 1
  • 4
  • 5