Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

tsconfig paths of node_modules/* not referenced in readme #27

Closed
mtpultz opened this issue Jul 19, 2017 · 3 comments
Closed

tsconfig paths of node_modules/* not referenced in readme #27

mtpultz opened this issue Jul 19, 2017 · 3 comments

Comments

@mtpultz
Copy link

mtpultz commented Jul 19, 2017

Noticed in the readme you only mentioned tconfig paths for src/types, but in your tsconfig you have node_modules/* even though you mentioned in the readme that node_modules/@types is already a default.

Is this a check for any types included within their own packages, or a mistake?

By the way thanks so much for this repo. I have gone through it all piece by piece while referencing your readme so I can pull over my new TypeScript skills from Angular into Node/Express. Your readme is the gold star for getting up and going with Node and TypeScript, as well as npm scripts, best practices, and helpful associated packages.

@bowdenk7
Copy link
Contributor

This isn't a mistake, but I thought it might make it clear for those who didn't read the readme that node_modules/* is included by default. So effectively this line does nothing.

I'd definitely be open to removing it. What do you think?

Glad you found this helpful. Any ideas for improvements?

@mtpultz
Copy link
Author

mtpultz commented Jul 21, 2017

Got it thanks.

Your suggestion in the readme on some testing if anyone is interested would be helpful, but there are a lot of resources already on testing so maybe links to ones you found particular useful would be a better use of time.

I think I have more questions then suggestions since I'm not sure what I don't know yet. I'm just reading through passport to find out how to do JWT authentication. I think with node my biggest worries are whether what I'm making is secure or not outside of HTTPS and SQL Injection. Typically, our APIs are done in Laravel, and a lot of the security is handled.

Is there a reason to setup the Express app in TypeScript without using classes? I found an example creates a class for the app instead and then loads everything up, which is what I'd do in an Angular application, but was wondering if that is a good idea for Node/Express:

app.ts

import * as express from 'express'

class App {  
  public express

  constructor () {
    this.express = express()
    this.mountRoutes()
  }

  private mountRoutes (): void {
    const router = express.Router()
    router.get('/', (req, res) => {
      res.json({
        message: 'Hello World!'
      })
    })
    this.express.use('/', router)
  }
}

export default new App().express  

Then server.ts would only need to start the server:

server.ts

import app from './App'

const port = process.env.PORT || 3000

app.listen(port, (err) => {  
  if (err) {
    return console.log(err)
  }

  return console.log(`server is listening on ${port}`)
})

@bowdenk7
Copy link
Contributor

That's a great idea. I'll post some of the links that I found helpful on testing when I get a chance.

On the security front, I am far from an expert so I'll leave those questions for someone more knowledgeable.

As far as classes go, classes are perfectly valid. The only reason I didn't use them here is because most people set up their express apps without them so I want the code to look familiar. In addition, some people believe TypeScript forces you to use classes, and I find it to debunk that myth.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants