0

I'm trying to run 'npm start' from a file : test.js . I get :

(function (exports, require, module, __filename, __dirname) { npm start
                                                              ^^^^
SyntaxError: Unexpected identifier

The content of test.js :

npm start 

What I'm trying to achieve is to avoid starting my node server with npm start directly in the shell and start it with:

node test.js

And programmatically restart my node server at three differents hours a day.

I'm not node expert. Can anyone help me or give me ideas to achieve this ? Thank you.

John
  • 185
  • 1
  • 6
  • 21
  • Do you have a package.json file? if not then run `npm init` and make one.After that use `npm start` – Mohhamad Hasham Jan 31 '18 at 17:26
  • As your primary target require running system command from Node.js, you may try this https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js – Ratul Sharker Jan 31 '18 at 17:29
  • @ Mohhamad Hasham yes i have a package.json file – John Jan 31 '18 at 18:23
  • Id like a valid answer to this not just using npm, please? I need to run a profiler on many unit tests, but within IntelliJ, you can't run a profiler against an npm script, you have to run it against an executed file in node. – Gdfelt Nov 21 '22 at 18:08

1 Answers1

1

npm start is not a valid javascript code rather it is a command meant to be used from the terminal. To do scheduled restarts you can use modules like pm2.

shawon191
  • 1,945
  • 13
  • 28