node.js - 使用 typescript 运行 node express 应用程序
问题描述
我创建了一个带有 typescript 支持的简单 node express 应用程序。有主要的index.tsx文件:
import express from 'express';
import cors from 'cors';
import GetDta from './src/discogs_api/services'
const app = express()
const port = 3000
app.use(cors());
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get('/OAuth', (req, res) => {
res.send('OAuth\'ing!...')
GetDta()
})
app.listen(port, () => {
console.log(`CORS Example app listening at http://localhost:${port}`)
})
现在,当我想使用以下方式运行应用程序时:
npx nodemon -e tsx index.tsx
我收到一个错误:Cannot use import statement outside a module.
当我将文件扩展名更改为ts我运行时没有任何问题时,更奇怪的是。为什么我不能使用tsx扩展?
解决方案
推荐阅读
- mysql - 如何在 SQL Select 语句中编写条件
- android - Android:在 WebViewCient.shouldOverrideUrlLoading 中未找到用于处理查看 HTTPS 网站的意图的活动
- cognos - 我无法获得百分比
- python - 类型错误:+ 不支持的操作数类型:“NoneType”和“float”,同时循环和添加
- javascript - 如何在 React/TS 中设置变量
- python - 鼠标点击事件pygame
- python - 从 csv 读取重复或重复的列并将它们附加到公共列中 -Pandas
- python-3.x - Django中的Redis性能很慢
- spring-boot - 在不扩展 WebSecurityConfigurerAdapter 的情况下访问 Global AuthenticationManagerBuilder?
- regex - 正则表达式:如何使用正则表达式捕获特定的数字字符串,但当字符串位于 URL 文本中时不捕获?