This post was first published on my blog.
Recently, I was working on TypeScript. I asked a question about TypeScript. Dev users helped me.
In th...
For further actions, you may consider blocking this person and/or reporting abuse
One thing you could do is also add nodemon into the mix.
remy / nodemon
Monitor for any changes in your node.js application and automatically restart the server - perfect for development
nodemon
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for
node
. To usenodemon
, replace the wordnode
on the command line when executing your script.Installation
Either through cloning with git or by using npm (the recommended way):
And nodemon will be installed globally to your system path.
You can also install nodemon as a development dependency:
With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as
npm start
) or usingnpx nodemon
.Usage
nodemon wraps your application, so you…
There are VS Code recipes to handle this.
Specifically this one, github.com/microsoft/vscode-recipe...
Even if you don't use VS Code, the tips provided are still helpful (see the npm scripts in the repo).
One thing I would recommend is to not use
ts-node
for production as you currently are for yournpm start
script. The reason being is it is a debugging/dev tool, much likebabel-node
. Consider transpiling and running thedist/server.js
with good ol' node.Looking forward to your next post!
Thanks, Nick.
I'm usually using the VS Code. I never heard the vscode-recipes before.
I'm trying to best :)
I don't remember clearly but I may have used nodemon before. It worked so slow on my computer. I know, it depended on my computer. I use a really old laptop.
Again I will say, these recipes are really helpful to me.
Thanks :)
Hey Ali, thanks for the post I've learned something as I am new to typescript.
I just found that if you want to import express instance you must do it this way
import express from 'express' not import * as express from 'express'
Typescript detect that as an error.
I have a question, I am just learning typescript, I do not understand this.
private middlewares(middleWares: { forEach: (arg0: (middleWare: any) => void) => void; })
what does { forEach: (arg0: (middleWare: any) => void) => void; } this do?
why could you not do this?
private middlewares(middleWares: any)
@edwin , this is very easy to understand if you already understand type of interface in typescript
You can write the same thing like this
interface arg{
(ar)=>void
}
interface middlewareInter{
forEach:(argument:arg)=>void // look at forEach function in js how it written
}
private middlewares(middlew:middlewareInter){
}
it return void because don't wanna handle the result there. void is a type in typescript which just tell that the function does not return anything
Nice article. I've got a question and a suggestion. :)
The question: your "start" script is using ts-node, shouldn't it use node because it'd be an overkill otherwise? Maybe some performance issue?
The suggestion: in the following line, instead of not declaring the type of the parameter "next" which defaults to
any
, you can declare it of typeNextFunction
:So, to import
NextFunction
, you can replaceimport { Request, Response } from 'express'
with:When using express with typescript, the best u can do is to take a look into TS.ed.
For me, this is the absolute best solution, with decorators and a fairly great architecture.
I didn't know Ts.ED. It's amazing. ❤
Hey this is amazing starter code
Thanks for this tutorial. I managed to implement this with handlebars instead.
Thank you for the tutorial. Saved me hours of rummaging around google searches!
Thanks for this informative post :thumbUp:
I had some issue with the setup of the express typescript project, But this is an enterprise level setup of the project.
Thank you keep writing good stuffs like this
Great Tutorial, learned a lot from it.!!