<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by RulerChen on Medium]]></title>
        <description><![CDATA[Stories by RulerChen on Medium]]></description>
        <link>https://medium.com/@RulerChen?source=rss-6a06da3f62a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k6WkMpaAhm2zCdXdGwP-dQ.jpeg</url>
            <title>Stories by RulerChen on Medium</title>
            <link>https://medium.com/@RulerChen?source=rss-6a06da3f62a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:59:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@RulerChen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Setup Node/Express.js Project with ESM、Typescript、Jest、Path alias in 2024]]></title>
            <link>https://medium.com/@RulerChen/how-to-setup-node-express-js-project-with-esm-typescript-jest-path-alias-in-2024-a0b4a4c07b4c?source=rss-6a06da3f62a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0b4a4c07b4c</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[RulerChen]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 02:31:29 GMT</pubDate>
            <atom:updated>2026-02-14T00:44:14.238Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ultimate Node/Express.js Project Setup Guide with ESM, Eslint, Prettier, Typescript, Jest, Path alias in 2024</h3><h3>Introduction</h3><p>In this article, I will show you how to setup a new Express.js project with ESM、Typescript、Jest、Prettier、ESLint and Path alias.</p><p>You can do it manually or use the <strong>gen-express-cli</strong> to generate a new project with the following command:</p><pre>npx gen-express-cli@latest &lt;project-name&gt;</pre><h3>Step 1 — Create a new project</h3><p>First, create a new project with the following command:</p><pre>mkdir express-project<br>cd express-project<br><br>npm init -y</pre><h3>Step 2 — Install dependencies</h3><p>Paste the following code into your <strong>package.json</strong> file:</p><pre>{<br>  &quot;name&quot;: &quot;test&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;cross-env NODE_ENV=development nodemon -r tsconfig-paths/register --exec ts-node ./src/index.ts --files&quot;,<br>    &quot;start&quot;: &quot;cross-env NODE_ENV=production node ./build/src/index.js&quot;,<br>    &quot;build&quot;: &quot;tsc &amp;&amp; tsc-alias&quot;,<br>    &quot;lint&quot;: &quot;eslint ./src/**/*.ts --fix&quot;,<br>    &quot;format&quot;: &quot;prettier --write ./**/*.{ts,json}&quot;,<br>    &quot;test&quot;: &quot;jest --coverage=true -w=1 --forceExit --detectOpenHandles --watchAll=false --testPathPattern=src/__tests__ --testPathIgnorePatterns=build&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;cors&quot;: &quot;^2&quot;,<br>    &quot;dotenv&quot;: &quot;^16&quot;,<br>    &quot;express&quot;: &quot;^4&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;cross-env&quot;: &quot;^7&quot;,<br>    &quot;nodemon&quot;: &quot;^3&quot;,<br>    &quot;typescript&quot;: &quot;~5.3&quot;,<br>    &quot;ts-node&quot;: &quot;^10&quot;,<br>    &quot;@types/cors&quot;: &quot;^2&quot;,<br>    &quot;@types/express&quot;: &quot;^4&quot;,<br>    &quot;@types/node&quot;: &quot;^20&quot;,<br>    &quot;eslint&quot;: &quot;^8&quot;,<br>    &quot;eslint-config-prettier&quot;: &quot;^9&quot;,<br>    &quot;eslint-config-standard-with-typescript&quot;: &quot;^43&quot;,<br>    &quot;eslint-plugin-import&quot;: &quot;^2&quot;,<br>    &quot;eslint-plugin-n&quot;: &quot;^16&quot;,<br>    &quot;eslint-plugin-prettier&quot;: &quot;^5&quot;,<br>    &quot;eslint-plugin-promise&quot;: &quot;^6&quot;,<br>    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^6&quot;,<br>    &quot;eslint-plugin-jest&quot;: &quot;^27&quot;,<br>    &quot;prettier&quot;: &quot;^3&quot;,<br>    &quot;jest&quot;: &quot;^29&quot;,<br>    &quot;ts-jest&quot;: &quot;^29&quot;,<br>    &quot;@types/jest&quot;: &quot;^29&quot;,<br>    &quot;tsc-alias&quot;: &quot;^1&quot;,<br>    &quot;tsconfig-paths&quot;: &quot;^4&quot;,<br>    &quot;typescript-transform-paths&quot;: &quot;^3&quot;<br>  }<br>}</pre><p>Then, install the dependencies:</p><pre>npm install</pre><h3>Step 3 — Create a index.ts file</h3><p>Create a new file named <strong>src/index.ts</strong> with the following code:</p><pre>import express from &#39;express&#39;;<br>import dotenv from &#39;dotenv&#39;;<br>import cors from &#39;cors&#39;;<br><br>dotenv.config();<br><br>const app = express();<br>const PORT = process.env.PORT ?? 8000;<br><br>app.use(cors());<br>app.use(express.urlencoded({ extended: true }));<br>app.use(express.json());<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World&#39;);<br>});<br><br>app.listen(PORT, () =&gt; {<br>  console.log(`Server is running on port ${PORT}`);<br>});<br><br>export default app;</pre><h3>Step 4 — Setup TypeScript</h3><p>Create a new file named<strong> tsconfig.json</strong> with the following code:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;es6&quot;,<br>    &quot;module&quot;: &quot;NodeNext&quot;,<br>    &quot;moduleResolution&quot;: &quot;NodeNext&quot;,<br>    &quot;resolveJsonModule&quot;: true,<br>    &quot;baseUrl&quot;: &quot;.&quot;,<br>    &quot;outDir&quot;: &quot;build&quot;,<br>    &quot;sourceMap&quot;: true,<br>    &quot;strict&quot;: true,<br>    &quot;esModuleInterop&quot;: true,<br>    &quot;types&quot;: [&quot;node&quot;, &quot;jest&quot;],<br>    &quot;plugins&quot;: [<br>      {<br>        &quot;transform&quot;: &quot;typescript-transform-paths&quot;<br>      },<br>      {<br>        &quot;transform&quot;: &quot;typescript-transform-paths&quot;,<br>        &quot;afterDeclarations&quot;: true<br>      }<br>    ],<br>    &quot;paths&quot;: {<br>      &quot;@/*&quot;: [&quot;src/*&quot;]<br>    }<br>  },<br>  &quot;include&quot;: [&quot;process.env.d.ts&quot;, &quot;./**/*.ts&quot;],<br>  &quot;exclude&quot;: [&quot;node_modules&quot;]<br>}</pre><h3>Step 5 — Setup ESLint and Prettier</h3><p>Create a new file named <strong>.eslintrc.json</strong> with the following code:</p><pre>{<br>  &quot;env&quot;: {<br>    &quot;es2021&quot;: true,<br>    &quot;node&quot;: true,<br>    &quot;jest/globals&quot;: true<br>  },<br>  &quot;extends&quot;: [&quot;standard-with-typescript&quot;, &quot;prettier&quot;],<br>  &quot;plugins&quot;: [&quot;jest&quot;, &quot;prettier&quot;],<br>  &quot;parserOptions&quot;: {<br>    &quot;ecmaVersion&quot;: &quot;latest&quot;,<br>    &quot;sourceType&quot;: &quot;module&quot;<br>  },<br>  &quot;rules&quot;: {<br>    &quot;prettier/prettier&quot;: [<br>      &quot;error&quot;,<br>      {<br>        &quot;semi&quot;: true,<br>        &quot;tabWidth&quot;: 2,<br>        &quot;printWidth&quot;: 140,<br>        &quot;singleQuote&quot;: true,<br>        &quot;bracketSameLine&quot;: false,<br>        &quot;trailingComma&quot;: &quot;all&quot;,<br>        &quot;arrowParens&quot;: &quot;always&quot;<br>      }<br>    ]<br>  }<br>}</pre><p>Create a new file named <strong>.prettierrc</strong> with the following code:</p><pre>{<br>  &quot;semi&quot;: true,<br>  &quot;printWidth&quot;: 140,<br>  &quot;tabWidth&quot;: 2,<br>  &quot;singleQuote&quot;: true,<br>  &quot;bracketSpacing&quot;: true,<br>  &quot;trailingComma&quot;: &quot;all&quot;,<br>  &quot;arrowParens&quot;: &quot;always&quot;<br>}</pre><h3>Step 6 — Setup Jest</h3><p>Create a new file named <strong>jest.config.ts</strong> with the following code:</p><pre>import type { JestConfigWithTsJest } from &#39;ts-jest&#39;;<br><br>const config: JestConfigWithTsJest = {<br>  verbose: true,<br>  transform: {<br>    &#39;^.+\\.ts?$&#39;: [<br>      &#39;ts-jest&#39;,<br>      {<br>        useESM: true<br>      }<br>    ]<br>  },<br>  extensionsToTreatAsEsm: [&#39;.ts&#39;],<br>  moduleNameMapper: {<br>    &#39;^(\\.{1,2}/.*)\\.js$&#39;: &#39;$1&#39;,<br>    &#39;@/(.*)&#39;: [&#39;&lt;rootDir&gt;/src/$1&#39;]<br>  }<br>};<br><br>export default config;</pre><h3>Step 7 — Test your project</h3><p>Run the following command to test your project:</p><pre>npm run dev</pre><p>Open your browser and visit <strong>http://localhost:8000</strong>, you will see <em>Hello World</em>.</p><p>To compile your typescript code, run the following command:</p><pre>npm run build<br>npm start</pre><p>To lint your code, run the following command:</p><pre>npm run lint</pre><p>To format your code, run the following command:</p><pre>npm run format</pre><p>To test your code, run the following command:</p><pre>npm test</pre><p>To import modules with path alias, you can use the following code:</p><pre>import &lt;module_name&gt; from &#39;@/module_name&#39;; // recommended<br>import &lt;module_name&gt; from &#39;../../../module_name&#39;; // not recommended</pre><h3>Conclusion</h3><p>If you like this article, please give me a star on <a href="https://github.com/RulerChen/gen-express-cli">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0b4a4c07b4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>