Giter Site home page Giter Site logo

Comments (3)

mtpultz avatar mtpultz commented on May 3, 2024 2

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}`)
})

from typescript-node-starter.

bowdenk7 avatar bowdenk7 commented on May 3, 2024

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?

from typescript-node-starter.

bowdenk7 avatar bowdenk7 commented on May 3, 2024

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.

from typescript-node-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.