简体   繁体   中英

express.js run endpoint from the command line

I have an express back end and mongodb database. I want to run a maintenance task to do some deletion of stale data in the db. The easiest and quickest way I can think to do this is use my existing code (database connection, app.js with all of the express setup, etc.) and setup a new route (ex. maintenance.js) that performs the task.

My question is how to hit the endpoint from the command line? Just running node maintenance.js won't actually cause the endpoint to execute unless I'm mistaken. My understanding is it will just make the endpoint accessible on the port the process is running on. My thought is maybe I serve the endpoint in one command line and run some command to hit it from another command line tab? Appreciate the help!

You can use mongo database connection string to connect to database using Mongo shell.

mongo <URI_string>

After the connection gets established. Use shell commands for query and deletion.

https://docs.mongodb.com/manual/reference/connection-string/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM