10/31/2023 0 Comments Expressjs typescriptNow you’re ready to get started with your Node.js and TypeScript development. Meaning, we get to write shiny new TypeScript, a superset of JavaScript, without having to worry too much about different environments. One of my biggest gripes with Node.js (especially with Serverless Lambda functions) is having to use the CommonJS require('module-name') syntax and lack of import/export keywords, which you’ll see our ES5 version “backports”. It’s pretty similar, but you’ll notice it’s just ES5 which can run pretty much everywhere with no problems. Let’s install the types for the packages that don’t ship with them be default: For anything else, their type definitions can usually be found on Definitely Typed. Most of these packages ship with type definitions for TypeScript, so we can start using them right away. rimraf is essentially a cross-platform rm -rf for Node.js so we can delete older copies of our dist directory before recompiling a new dist.helmet adds some sensible default security Headers to your app.express is a framework for building APIs, such as handling GET, POST, PUT, DELETE requests with ease and building your application around it.env variables into process.env so we can access them inside our *.ts files. cross-env sets environment variables without us having to worry about the platform.body-parser extracts the entire body of an incoming request stream (for Express) and exposes it on req.body as something easier to work with, typically using JSON.Here are some further details on each of those: Npm i body-parser cross-env dotenv express helmet rimraf
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |