英文:
how can I start my express server with nodemon with commands in package.json?
问题
I can start my server with nodemon src/server.ts but I want it to start via package.json with a command like npm start.
How can I do it?
I have seen a tutorial but it doesn't work; it shows me an error, the command is wrong:
"start:nodemon": "./node_modules/nodemon/bin/nodemon.js",
from this site
enter link description here
Here is my package.json:
{
"name": "express_inngest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "ts-node ./src/server.ts",
"start:nodemon": "./node_modules/nodemon/bin/nodemon.js",
"start:prod": "npm run build && node ./dist/src/server.js",
"build": "npx tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.17",
"@types/node": "^20.4.9",
"nodemon": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
nodemon json:
{
"ignore": [".git", "node_modules", "dist"],
"watch": ["./src"],
"exec": "npm start",
"ext": "ts"
}
英文:
I can start my server with nodemon src/server.ts but I want it start via package.json with command like npm start.
How can I do it ?
I have seen a tutorial but it not works it shows me a error the command is wrong:
"start:nodemon": "./node_modules/nodemon/bin/nodemon.js",
from this site
enter link description here
Here is my package.json
{
"name": "express_inngest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "ts-node ./src/server.ts",
"start:nodemon": "./node_modules/nodemon/bin/nodemon.js",
"start:prod": "npm run build && node ./dist/src/server.js",
"build": "npx tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.17",
"@types/node": "^20.4.9",
"nodemon": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
nodemon json
{
"ignore": [".git", "node_modules", "dist"],
"watch": ["./src"],
"exec": "npm start",
"ext": "ts"
}
答案1
得分: 1
这里是一个我使用你的目录结构的配置,没有太多需要解释的。
// package.json
"scripts": {
"start": "nodemon",
"start:raw": "ts-node ./src/server.ts",
"start:prod": "npm run build && node ./dist/src/server.js",
"build": "npx tsc"
},
// nodemon.json
{
"ignore": [".git", "node_modules", "dist"],
"watch": ["./src"],
"exec": "ts-node ./src/server.ts",
"ext": "ts"
}
因此,你可以像这样更新你的配置。
英文:
There is not much to explain, here is a config for I use your directory structure.
//package.json
"scripts": {
"start": "nodemon",
"start:raw": "ts-node ./src/server.ts",
"start:prod": "npm run build && node ./dist/src/server.js",
"build": "npx tsc"
},
// nodemon.json
{
"ignore": [".git", "node_modules", "dist"],
"watch": ["./src"],
"exec": "ts-node ./src/server.ts",
"ext": "ts"
}
so, you can update your config like this
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论